.htaccess locally

Discussion in 'Apache' started by protocol96, Apr 27, 2007.

  1. #1
    i am on opensuse linux machine, i need to verfiy if the 301 redirect will work properly, so i want to check it locally first, i have created a .htaccess file in my htdocs folder
    and have the following lines in it

    Options +FollowSymlinks
    RewriteEngine on
    rewritecond %{http_host} ^domain.com [nc]
    rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]

    but it aint working, can someone tell me , how to go about it?
     
    protocol96, Apr 27, 2007 IP
  2. rodney88

    rodney88 Guest

    Messages:
    480
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    0
    #2
    How do you want to test that locally? It checks if the domain is "domain.com" and redirects to www.domain.com. Locally, the %{HTTP_HOST} variable will be "localhost" (!= "domain.com") so your RewriteCond will prevent the RewriteRule being processed. I don't know what you mean by it doesn't work, but if you mean nothing happens then that's probably because nothing should happen.

    If you want to make sure it's working without sending a permanently moved 301 header, just remove the =301 value from the R flag. Then by default it will send a 302 temporarily moved header and if for any reason your redirect isn't working as desired you can change it without worrying about any permanent side-effects from having sent people to the wrong location.
     
    rodney88, Apr 27, 2007 IP
  3. protocol96

    protocol96 Peon

    Messages:
    413
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Options +FollowSymlinks
    RewriteEngine on
    rewritecond %{http_host} ^192.168.1.2/test.html [nc]
    rewriterule ^(.*)$ http://www.google.com/$1 [r=301,nc]

    wat i did was, i went to other machine and typed http:// 192.168.1.2/test.html but it still gave me the content of test file and not redirect it to www.google.com., i have also enabled the rewrite module
     
    protocol96, Apr 27, 2007 IP
  4. rodney88

    rodney88 Guest

    Messages:
    480
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    0
    #4
    The only values the HTTP_HOST can take are 192.168.1.2, localhost, domain.com, sub.domain.com, etc.

    /test.html is not part of the hostname. It seems like a fairly pointless test as the code is getting very different from what you're actually going to use but anyway:
    Options +FollowSymLinks
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^192.168.1.2$ [nc]
    RewriteRule ^test\.html$ [url]http://www.google.com/[/url] [R=301,NC]
    Code (markup):
    should redirect test.html to google.com
     
    rodney88, Apr 27, 2007 IP
  5. protocol96

    protocol96 Peon

    Messages:
    413
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Options +FollowSymLinks
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^localhost$ [nc]
    RewriteRule ^test\.html$ http://www.google.com/ [R=301,NC]

    i have tried this too, but it aint working
     
    protocol96, Apr 27, 2007 IP
  6. protocol96

    protocol96 Peon

    Messages:
    413
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #6
    hey, i dunno y it wasnt working in .htaccess file but wen i added this httpd.conf file it started working,
    So another question, i have a sub-domain for which i m raking pretty well but i need to move the sub-domain to another link,
    abc.example.com to www. domain.com/home/furniture/article?id=234.

    using 301 redirect i wont lose serp rankings, so wat will happen to my inner SERP pages, for ex: wat will happen to abc.example.com/watever/house/home/article.php

    thanks for help guyz.
     
    protocol96, Apr 28, 2007 IP