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
    #181
    Redirect like...

    Options +Indexes
    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /
    RewriteRule ^shop/([^.]+)$ http://www.domain.com/$1/ [R=301,L]
    or
    RewriteRule ^whatever/$ http://www.domain.com/ [R=301,L]

    If you don't have the PR now...I think you'll have to waite until the next update to get it back! This just moves existing PR, and makes the old URL go to the new URL!!!!
     
    Nintendo, Dec 27, 2005 IP
  2. vishwaa

    vishwaa Well-Known Member

    Messages:
    271
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    138
    #182
    Great tutorial...

    Now all my URLs become static. Thanks Nintendo!

    Adding to php->html mod rewriting, I want to give a 301 redirect to the dynamic pages listed SE. Any ideas to implement it? I ended up with infinite loop.
     
    vishwaa, Jan 14, 2006 IP
  3. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #183
    You can't give the same URLs both mod_rewrite and redirect, or they go to war at each other!!!!!
     
    Nintendo, Jan 14, 2006 IP
    Hon Daddy Dad likes this.
  4. Hon Daddy Dad

    Hon Daddy Dad Peon

    Messages:
    1,041
    Likes Received:
    49
    Best Answers:
    0
    Trophy Points:
    0
    #184
    You're the king nintendo! I got all my mod_rewrites working sweet as.
     
    Hon Daddy Dad, Jan 23, 2006 IP
  5. CaptainJoe

    CaptainJoe Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #185
    Hi Nintendo:

    I have encountered bit of a google high ranking mystery and am wondering if you think that mod_rewrite might have something to do with it.

    If you put in the term "rimage" in google, this subdomain name comes up ranked as number 2: http://rimage.cd-lab.com

    I think the great ranking is only because its a subdomain with the term "rimage" in it and its using mod_rewrite?

    I cant find any other content for this subdomain and it has relatively low pagerank. when I click on any link on the subdomain page, it immediately reverts to the main domain name www.cd-lab.com.

    I am considering using this subdomain "technique" (?) for various vendor names (like "rimage") to get better ranking. Does it make sense for me to this as a valid SEO technique.

    CJ
     
    CaptainJoe, Jan 23, 2006 IP
  6. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #186
    Title, header, and URL all have it, hince it's at the top!!! URL helps big time!!
     
    Nintendo, Jan 23, 2006 IP
  7. ian_ok

    ian_ok Peon

    Messages:
    551
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #187
    I'm changing two sections of my site, so that all images are on the same page as the relevant information as oppose to individual pages, so this means hundreds of Redirect 301's, can I minimise this down anyway??

    1st - I have - pic_ref_a/number.php redirected to ref_a.php

    redirect 301 /folder/ref_a.php http://www.site.com/folder/pic_ref_a/1.php
    redirect 301 /folder/ref_a.php http://www.site.com/folder/pic_ref_a/2.php
    redirect 301 /folder/ref_a.php http://www.site.com/folder/pic_ref_a/3.php

    Then
    redirect 301 /folder/ref_b.php http://www.site.com/folder/pic_ref_b/1.php
    redirect 301 /folder/ref_b.php http://www.site.com/folder/pic_ref_b/2.php

    ETC....... Can I reduce this???

    2nd - With this I think I can't do anything as each image ID relates to a certain property ID and unless you know the image id you don't know which property it relates too!

    redirect 301 /folder/image.php?imageID=74&type=listing http://www.site.com/folder/listingview.php?listingID=10


    Also how long should you keep a 301 redirect active for??

    Thanks for any help.

    Ian
     
    ian_ok, Jan 23, 2006 IP
  8. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #188
    If they all go to the same place, from

    folder/pic_ref_a/ANY NUMBER.php to /folder/ref_SAME LETTER.php

    Options +Indexes
    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /
    RewriteRule ^folder/pic_ref_a/([^.]+)\.php$ http://www.domain.com/folder/ref_a.php [R=301,L]
    RewriteRule ^folder/pic_ref_b/([^.]+)\.php$ http://www.domain.com/folder/ref_b.php [R=301,L]

    I've used redirect twice and havn't took it down.
     
    Nintendo, Jan 24, 2006 IP
  9. ian_ok

    ian_ok Peon

    Messages:
    551
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #189
    Thnaks for that Nintendo, works a treat.

    Keep feeding that rat and you might work a miricle on it!

    Thanks again.

    Ian
     
    ian_ok, Jan 24, 2006 IP
  10. bbk

    bbk Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #190
    I have a 700-page travel site. The original pages had simple, SEO-friendly page names ending in .jsp. We were in the process of migrating to a PHP server and are using HTAccess to read the .jsp pages as if they were .html pages....but now I'm leaning instead towards having someone rebuild the site in Drupal or another CMS. It would make my life so much easier.

    Many of our current pages are well-ranked in the search engines, and I don't want to lose that. However, we're a new site, so we don't have that many incoming links yet.

    If I use Drupal, the only change I'd need to make to the page name, I believe, is to lose the .jsp extension. If I do that, and use a 301 redirect, from a search engine's perspective, have I lost anything at all?

    (If yes, then can/should I use HTAccess or ModRewrite to have Drupal add the .jsp extensions to my page names?)
     
    bbk, Jan 25, 2006 IP
  11. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #191
    You can't do both mod_rewrite AND 301 redirect for a old and new URL. The URLs will fight over each other!! No, rewrite, no redirect, no, rewrite, no redirect...
     
    Nintendo, Jan 25, 2006 IP
  12. Dekker

    Dekker Peon

    Messages:
    4,185
    Likes Received:
    287
    Best Answers:
    0
    Trophy Points:
    0
    #192
    Dekker, Jan 25, 2006 IP
  13. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #193
    I havn't tried it, but if it's just an extension change, include the domain name in the left URL AND extension instead of just domain.com. I'm guessing that would work.
     
    Nintendo, Jan 26, 2006 IP
  14. joewills

    joewills Peon

    Messages:
    44
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #194
    Hi

    I am trying to allow a web page with a php extension to be written with a html extension.

    And after changing a bit of code that I foun online this seemed to work....

    RewriteEngine on
    RewriteCond %{SERVER_PORT} ^80$
    RewriteRule (.*/)([^.]+)\.php /$1$2%2.html?%1%3 [R]

    from
    http://www.mydomain.com/content/catergories.php
    to
    http://www.mydomain.com/content/catergories.html

    This kinda worked... in terms of the url it translated it fine - but the functionality of the php page did not. The catergories.php consisted of a template which used some php variables. It also referenced (as main body of template) to a html page - infocatergories.html.

    The results of the above action meant that only the html page (infocatergories.html) was shown and none of the template that was setup using templates and php.

    What am I doing wrong? or is this normal and a limitation?

    Thanks in advance,

    Joe

    p.s. do search engines prefer *.htm or *.html (No worries if that is a very subjective thing and a whole new post on its own)
     
    joewills, Jan 26, 2006 IP
  15. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #195
    Options +Indexes
    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /
    RewriteRule ^([^.]+)/([^.]+)\.html$ $1/$2.php [L]

    or for one file...

    RewriteRule ^content/catergories\.html$ content/catergories.php [L]
     
    Nintendo, Jan 26, 2006 IP
  16. joewills

    joewills Peon

    Messages:
    44
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #196
    Hi - thanks for the swift reply :)

    I think I was getting a bit mixed up with redirecting and transforming the url!!

    I have fiddled around experimenting with .htaccess file.

    Previously I have been able to 1) redirect a page and 2) tranform the url - and still point to the same page.

    For some reason I can now only redirect.

    I am using the exact same code and entering it into the .htaccess file as before.

    the code is:


    RewriteEngine on
    RewriteCond %{SERVER_PORT} ^80$
    RewriteRule ^listings/([A-Za-z]+)_times\.html$ /includes/listings\.php?srchBox1=$1


    I also tied RewriteRule ^([^.]+)/([^.]+)\.html$ $1/$2.php [L] as suggested, but with no joy....

    Any suggestions please?

    Joe
     
    joewills, Jan 27, 2006 IP
  17. soul-healer

    soul-healer Peon

    Messages:
    1,459
    Likes Received:
    145
    Best Answers:
    0
    Trophy Points:
    0
    #197
    Hi,

    I got a .htaccess mod to create dynamic SubDomain Style URLs for my users. I want to ask is it possible to have group of subdomain hosted on different IP address?

    Regards.
     
    soul-healer, Jan 27, 2006 IP
  18. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #198
    I havn't ever been able to do both, due to the infinite loof, it fighting over what it wants to do, change URL, or redirect.

    Make a new thread for that. I've never done sub-domain stuff.
     
    Nintendo, Jan 27, 2006 IP
  19. joewills

    joewills Peon

    Messages:
    44
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #199
    The problem I am now facing is that I can no longer transform the url address at all. I am no longer trying to redirect

    I have just :

    RewriteEngine on
    RewriteCond %{SERVER_PORT} ^80$
    RewriteRule ^listings/([A-Za-z]+)_times\.html$ /includes/listings\.php?srchBox1=$1

    in the .htaccess file

    Is there something that I may have changed that needs re-setting. The reason I ask is beacause I am sure the above code worked a couple of days ago.

    Cheers,

    Joe
     
    joewills, Jan 27, 2006 IP
  20. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #200
    Options +Indexes
    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /
    RewriteRule ^listings/([^.]+)_times\.html$ includes/listings.php?srchBox1=$1 [L]
     
    Nintendo, Jan 27, 2006 IP