Need help with 301 redirection

Discussion in 'Apache' started by learner4ever, Jul 29, 2010.

  1. #1
    Hi All, my site is hosted on apache server. I was trying to redirect (301) the non www version of my website to www. The code i was using in my .htaccess file was:

    RewriteEngine On

    rewritecond %{http_host} ^domain.com

    rewriterule ^(.*)$ [domain.com...] [r=301,L]

    I have tried the same code earlier on my other websites and it had worked bt now its not working. When I upload htaccess file with above code, i get an 500 Internal Server Error.Can you people suggest any thing.
    One more thing that i have found that there are around 5-6 .htaccess file in various folders like vti_log, vti_cnf and others with code:

    # -FrontPage-

    IndexIgnore .htaccess */.?* *~ *# */HEADER* */README* */_vti*

    <Limit GET POST>
    order deny,allow
    deny from all
    allow from all
    </Limit>
    <Limit PUT DELETE>
    order deny,allow
    deny from all
    </Limit>
    AuthName domain.com
    AuthUserFile /home/folder/public_html/_vti_pvt/service.pwd
    AuthGroupFile /home/folder/public_html/_vti_pvt/service.grp

    Does this code have anything to do with my problem and what the above code mean. Please help.
     
    learner4ever, Jul 29, 2010 IP
  2. learner4ever

    learner4ever Peon

    Messages:
    33
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Ok I figure out the code partially that is authentication code + setting code for view & change the files. Now 2 questions:
    1. Could anybody tell me why my redirecting code is not working with this code. (when i upload the above redirection code with these lines of code, I got an internal 500 server error)
    2. Are these lines of code correct:
    <Limit GET POST>
    order deny,allow
    deny from all
    allow from all
    </Limit>

    Please help.........
     
    learner4ever, Jul 29, 2010 IP
  3. tolra

    tolra Active Member

    Messages:
    515
    Likes Received:
    36
    Best Answers:
    1
    Trophy Points:
    80
    #3
    Move the existing .htaccess out of the way and then put the following in an empty .htaccess, obviously changing the domain name to yours:
    
    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^www\.tolranet\.co\.uk [NC]
    RewriteRule (.*) http://www.tolranet.co.uk/$1 [R=301,L]
    
    Code (markup):
    If you still get the 500 error then log a ticket with your host asking them if mod_rewrite is enabled if not can it be, your host should be in the best position to debug this for you.

    Assuming the above works then add in the <Limit and other items you need from your stored .htaccess, just add one thing at a time if it stops working you know the last thing you added was the cause of the issue and we can go from there.
     
    tolra, Jul 30, 2010 IP
  4. learner4ever

    learner4ever Peon

    Messages:
    33
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    can u please tell me why have u used www in this line: RewriteCond %{HTTP_HOST} !^www\.tolranet\.co\.uk [NC]
    as i am writing for a condition that if somebody tells the url without non www then redirect it to www
     
    learner4ever, Jul 30, 2010 IP
  5. tolra

    tolra Active Member

    Messages:
    515
    Likes Received:
    36
    Best Answers:
    1
    Trophy Points:
    80
    #5
    It says if it is NOT www.tolranet.co.uk then rewrite it.

    This is the version I give to our clients as that way when they park another domain on top or some such the rewrite rule just works without them having to add the new domain.
     
    tolra, Jul 30, 2010 IP
  6. learner4ever

    learner4ever Peon

    Messages:
    33
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Oh yes, i just forgot the wild character meaning. Thanks the redirection code is working fine now. Now i have to check for other code. Thanks once again.
     
    learner4ever, Jul 30, 2010 IP
  7. tolra

    tolra Active Member

    Messages:
    515
    Likes Received:
    36
    Best Answers:
    1
    Trophy Points:
    80
    #7
    If you find it issues a 500 again, just post up your whole .htaccess along with which bit you added to cause the failure and I'll see what I can do.
     
    tolra, Jul 30, 2010 IP
  8. learner4ever

    learner4ever Peon

    Messages:
    33
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    No its working fine now. I have uploaded with all the code. have placed the redirection code on top then other lines of code.
     
    learner4ever, Jul 30, 2010 IP
  9. tolra

    tolra Active Member

    Messages:
    515
    Likes Received:
    36
    Best Answers:
    1
    Trophy Points:
    80
    #9
    Opps, misread that, glad to hear it :)
     
    tolra, Jul 30, 2010 IP
  10. learner4ever

    learner4ever Peon

    Messages:
    33
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    :) :) :) :)
     
    learner4ever, Jul 30, 2010 IP
  11. learner4ever

    learner4ever Peon

    Messages:
    33
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    hi can you tell me one more thing. what would be the code to redirect an old url to a new url?
     
    learner4ever, Jul 30, 2010 IP
  12. tolra

    tolra Active Member

    Messages:
    515
    Likes Received:
    36
    Best Answers:
    1
    Trophy Points:
    80
    #12
    Redirect 301 /old.html /new.html
     
    tolra, Jul 30, 2010 IP