FAQ: mod_rewrite, 301 redirects, and optimizing Apache.

Discussion in 'Apache' started by Nintendo, Jul 30, 2005.

  1. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #301
    You don't even have mod_rewrite working!!!!
     
    Nintendo, Jun 1, 2006 IP
  2. The Webmaster

    The Webmaster IdeasOfOne

    Messages:
    9,516
    Likes Received:
    718
    Best Answers:
    0
    Trophy Points:
    360
    #302
    I dont know what is wrong. I told ya I am a Win guy, Ask me about ASP/ .net
    mod_rewrite/nix is an alien thing to me.

    Whenever I try to put rewrite rules in .htaccess file it gives me 500 error.
    though 301 redirect working.
    What can I do now, it will ruin my SERP/PR.
     
    The Webmaster, Jun 1, 2006 IP
  3. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #303
    Is this on a shared server or dedicated server hosted by a web hosting company, or do you have your own dedicated server in house? Many moons ago I had to edit an apache file for .htaccess stuff to work. I would get the Internal Server Error message with I tried .htaccess stuff.

    Post the 301 code that works.

    You can also try posting at *gags* webmasterworld.com/forum92/

    The Apache King is there.
     
    Nintendo, Jun 1, 2006 IP
  4. The Webmaster

    The Webmaster IdeasOfOne

    Messages:
    9,516
    Likes Received:
    718
    Best Answers:
    0
    Trophy Points:
    360
    #304
    I am better away from WMW.

    I put this line in .htaccess to resolve the WWW and Non-WWW issue and it worked - redirect 301 / http://www.sitename.com/

    But when i try to put this -
    Options +FollowSymLinks
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^site.com [NC]
    RewriteRule ^(.*)$ http://www.site.com/$1 [L,R=301]

    It has given 500 Server error, I dont know what to do.
    I transfered the whole site back on the windows hosting, but its temporary.
    I have to transfer 5 of my sites on linux hosting, and the bad part is 3 of them are in ASP translated to PHP.
     
    The Webmaster, Jun 3, 2006 IP
    Nintendo likes this.
  5. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #305
    Next time you get off Windows again, try a simple...

    RewriteEngine on
    RewriteBase /
    RewriteRule ^wacko101$ index.php [L]

    test, just in case the first two lines were the cause. domain.com/wacko101

    showing the index page. If that or the last test doesn't work, nothing will work. WMW might be your only hope. *gags*
     
    Nintendo, Jun 3, 2006 IP
  6. The Webmaster

    The Webmaster IdeasOfOne

    Messages:
    9,516
    Likes Received:
    718
    Best Answers:
    0
    Trophy Points:
    360
    #306
    What does it do? should I place it under site/Wacko101 dir
    or it would rename the index.php to wacko101 ???

    Edit: I have just dropped a mail to support to ask whether mod_rewrite is supported on the server.
     
    The Webmaster, Jun 3, 2006 IP
  7. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #307
    That's exactly the same at the last test with out the first two lines and with out a dot in the fake URL.

    domain.com/.htaccess
    (Same located at when the last test was made.)

    then

    domain.com/wacko101 would show da index page.
     
    Nintendo, Jun 3, 2006 IP
  8. The Webmaster

    The Webmaster IdeasOfOne

    Messages:
    9,516
    Likes Received:
    718
    Best Answers:
    0
    Trophy Points:
    360
    #308
    it worked, the test has worked.

    Edit: Damn it, The issue's resolved, the ASP page is redirecting to .htm pages
    Thanks a lot Ninno. You are da Man.errrrr....wacko Ninno

    Is there any way that I can rewrite .htm files as .asp?? or will it save my SERP/PR in da next update??
     
    The Webmaster, Jun 3, 2006 IP
  9. everton

    everton Peon

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #309
    I've only registered to say a big thank you Nintendo. I've spent the last 48 hours trying to work out how to redirect my and absolutely no-one has been able to help me.

    After reading your post I managed to crack it in 2 minutes, which I think is amazing given that I've never used apache before or done any coding.

    Thanks again
     
    everton, Jun 4, 2006 IP
  10. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #310
    Looks like it was just the first two lines in the first code that was 'destroying you'!!

    RewriteEngine on
    RewriteBase /
    RewriteRule ^(.*)\.html$ $1.asp [L]

    to let .asp URLs be .html

    Oh...mod_rewrite probably doesn't work on Windows and asp probably doesn't work on non-Windows!!! I think the redirect code is the only thing you can do

    RewriteEngine on
    RewriteBase /
    RewriteRule ^(.*)\.asp$ http://www.domain.com/$1.html [R=301,L]
     
    Nintendo, Jun 5, 2006 IP
  11. The Webmaster

    The Webmaster IdeasOfOne

    Messages:
    9,516
    Likes Received:
    718
    Best Answers:
    0
    Trophy Points:
    360
    #311
    Yepp that was the problem.
    they said that SymFollow was already activated, so there was no need to add that into the code. coz since it is already activated and when we tried to reactivate it, it trigered the server error.
    :)
    but Thanks a lot, it is solved and redirection is working now.

    Woohooo!!!

    And this worked too.
    U r da wacko, U r da wacko!!!

    done dona done
     
    The Webmaster, Jun 5, 2006 IP
  12. everton

    everton Peon

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #312
    Hi

    thanks for a great guide. I've used it to crack problems with moving my blog -even though I had no previous apache or even coding experience. Very well written.

    I need help with a rule. I need to rewrite the following which isn't working:

    # Redirect Old Searches
    RewriteRule ^blog?cmd=search&keywords=(.*)$ site/index.php?s=$1&submit= [R=301,L]


    The '?' in 'blog?cmd=search....' isn't a wildcard - it's actually part of the url. I think this is a problem as I think apache thinks it's a wildcard. How do I fix?

    Thanks in advance for any help.

    Everton
     
    everton, Jun 6, 2006 IP
  13. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #313
    site/index.php?s=$1&submit=

    needs the complete URL.
     
    Nintendo, Jun 6, 2006 IP
  14. everton

    everton Peon

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #314
    In my actual rule I have site in there. I put 'site' in this post as I'm not allowed to post urls yet as I've only just registered!

    It's the ? in the url to match that I think is causing the problem.

    Everton
     
    everton, Jun 7, 2006 IP
  15. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #315
    A \ can be placed before any characters that might cause trouble.

    Options +Indexes
    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /
    RewriteRule ^blog?cmd=search&keywords=([^.]+)$ http://www.domain.com/index.php?s=$1&submit= [R=301,L]
     
    Nintendo, Jun 7, 2006 IP
  16. Clubtitan.org

    Clubtitan.org Peon

    Messages:
    104
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #316
    Thanks for this tutorial. I have searched Google forever trying to find a way that would work to fix my problem of all my indexed pages in search engines not working. I had moved my forums from the root / directory to /forums. None of the links found in Google would work. I finally found this and had never even thought to look here. I have used this site quite a bit but never thought the answer to this would be here. Nintendo you are great man. Its people like you that make sites like this great. Keep up the good work. The site is working great now.
    I have a second problem on a different site though. I used to run a phpnuke site that I converted to vbulletin. I have thousands of links to the site but they dont work anymore. I know I probably have no way to redirect those links to the correct threads or posts but is there a way to redirect the indexed pages like this
    http://clubtitan.org/postp6673.html to point to my vbulletin index http://www.clubtitan.org/forums
    thanks again.
    Josh
     
    Clubtitan.org, Jun 15, 2006 IP
  17. Clubtitan.org

    Clubtitan.org Peon

    Messages:
    104
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #317
    Nevermind after reading more and trying a few things I got it.
    Used this
    RewriteEngine on
    Options +FollowSymLinks
    RewriteCond %{HTTP_HOST} ^clubtitan\.org
    RewriteRule ^(.*)\.html$ http://www.clubtitan.org/forums [L]

    Thanks
    Josh
     
    Clubtitan.org, Jun 15, 2006 IP
  18. johnnymac

    johnnymac Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #318
    hey there... got your message but I guess I'm thick... is the answer yes or no... a 301 redirect = mod_rewrite?

    cheers!
    Johnny Mac
     
    johnnymac, Jun 15, 2006 IP
  19. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #319
    mod_rewrite is changing URLs. That's not 'mod_rewrite'. It's a 301 redirect, redirecting from an old to new URL. To make for example Google redirect the page rank to the new URL.

    302 bad. 301 good.
     
    Nintendo, Jun 15, 2006 IP
    Clubtitan.org likes this.
  20. trung

    trung Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #320
    Hi all, anybody help me?

    In my .htaccess file:
    RewriteRule ^search_car/(.*)--(.*)/(.*)--(.*)/(.*)--(.*)/(.*)--(.*)/(.*)--(.*)\.html$ /cgi-bin/goo_mobile/NEW/search_static/search_car_w.cgi?$1=$2&$3=$4&$5=$6&$7=$8&$9=$10 [L]

    I can't get $10 value (but $1 to $9 is OK)?

    Thanks for your help.
     
    trung, Jun 19, 2006 IP