1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

.htaccess help please!

Discussion in 'Black Hat SEO' started by rugbyjack2005, Apr 4, 2013.

  1. rugbyjack2005

    rugbyjack2005 Power Member

    Joined:
    Oct 2, 2011
    Messages:
    539
    Likes Received:
    50
    Location:
    United Kingdom
    I have a new client that has recently moved their site to a new domain. While they have transferred most of their site to the new domain, they still have an application running on the old domain. This application has a login box with a bit of code in the .htaccess - see below:

    AuthUserFile /folder/folder/auth/.htpasswd1
    AuthGroupFile /dev/null
    AuthName "Private"
    AuthType Basic


    require valid-user

    Now i want to redirect the old site to the new site but with an exception that allows the application to still run on the old site. This is where i have got to so far but I am struggling with the exception part:

    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} !newdomain.com$ [NC]
    RewriteRule ^(.*)$ http://www.newdomain.com/$1 [L,R=301]


    AuthUserFile /folder/folder/auth/.htpasswd1
    AuthGroupFile /dev/null
    AuthName "Private"
    AuthType Basic


    require valid-user



    These two codes work individually but not together as i am missing the bit of exception code. Can someone fill in the missing bit of exception code please?

    Thanks add rep will naturally be given to useful comments.
     
  2. rugbyjack2005

    rugbyjack2005 Power Member

    Joined:
    Oct 2, 2011
    Messages:
    539
    Likes Received:
    50
    Location:
    United Kingdom
    Anyone?
     
  3. Stufferizer

    Stufferizer Jr. VIP Jr. VIP

    Joined:
    Nov 6, 2012
    Messages:
    276
    Likes Received:
    90
    I would suggest that you try stackoverflow or serverfault for such a technical question.

    Nevertheless, if your application has a certain string (footprint?!) in it you could try to use it as an exception like

    RewriteCond %{QUERY_STRING} !applicationquerrystring
     
  4. bobred

    bobred Junior Member

    Joined:
    Dec 21, 2011
    Messages:
    101
    Likes Received:
    63
    Try....

    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_URI} !^/folder/folder/auth
    RewriteCond %{HTTP_HOST} !newdomain.com$ [NC]
    RewriteRule ^(.*)$ http://www.newdomain.com/$1 [L,R=301]

    AuthUserFile /folder/folder/auth/.htpasswd1
    AuthGroupFile /dev/null
    AuthName "Private"
    AuthType Basic
     
    • Thanks Thanks x 1
  5. Zapdos

    Zapdos Power Member

    Joined:
    Oct 22, 2011
    Messages:
    597
    Likes Received:
    708
    Location:
    Eastern North Carolina
    Remove the "L," from the rewrite rule line. That may solve your problem depending on the setup.

    The alternative option is to add another condition to only rewrite when it doesnt match the URL you want to use.
     
  6. rugbyjack2005

    rugbyjack2005 Power Member

    Joined:
    Oct 2, 2011
    Messages:
    539
    Likes Received:
    50
    Location:
    United Kingdom
    Thanks. That seems to work on my test site. I'll have to wait till tomorrow to check for sure but it looks good so far
     
  7. bobred

    bobred Junior Member

    Joined:
    Dec 21, 2011
    Messages:
    101
    Likes Received:
    63
    Glad i could help, though i did miss off the "require valid-user" from my post which you will also need! And if you encounter any problems accessing the password protected pages with the new rules, you may need to add the following to your .htaccess

    ErrorDocument 401 "Unauthorised"

    EDIT - You may well find that you will need two seperate .htaccess files, one with the redirect in the root of your domain, and one with the auth directives and the ErrorDocument 401 "Unauthorised" line at the top in the folder that is to be protected.

    Good luck :)
     
    Last edited: Apr 4, 2013
  8. rugbyjack2005

    rugbyjack2005 Power Member

    Joined:
    Oct 2, 2011
    Messages:
    539
    Likes Received:
    50
    Location:
    United Kingdom
    Ok so we have tried it now on the actual site and the redirect works but the application running off the old site doesn't. Any ideas? Is it possible just to redirect certain pages rather than the whole site?