Help with redirect

Discussion in 'Site & Server Administration' started by Jhonne, Jan 27, 2010.

  1. #1
    RewriteEngine on
    RewriteCond %{SCRIPT_FILENAME} !-d
    RewriteRule ^([^\.]+)$ $1.html [NC,L]
    RewriteRule ^([^\.]+)$ $1.php [NC,L]

    RewriteCond %{REQUEST_URI} !(\.[^./]+)$
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule (.*) /$1.php [L]

    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^.]+\.)+html\ HTTP
    RewriteRule ^(.+)\.html$ /$1 [R=301,L]

    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^.]+\.)+php\ HTTP
    RewriteRule ^(.+)\.php$ /$1 [R=301,L]

    I have a homepage with mixed html and php pages. What I want is to remove the extensions
    and also redirect the old pages to the new extenionless pages. This is what I have come up
    with, is there any errors in this code or does it look as it should? is it SEO friendly?

    Thanks
     
    Jhonne, Jan 27, 2010 IP
  2. hans

    hans Well-Known Member

    Messages:
    2,923
    Likes Received:
    126
    Best Answers:
    1
    Trophy Points:
    173
    #2
    1.
    make sure the logical sequence is correct of the above listed multiple require cond/rules

    2.
    only 1 L per rule ...
    in your
    RewriteRule ^([^\.]+)$ $1.html [NC,L]
    RewriteRule ^([^\.]+)$ $1.php [NC,L]

    you have BOTH as L (last rule)

    3.
    make sure your NC or MISSING NC is correct
    and you have a 301 everyhwere where needed
     
    hans, Jan 28, 2010 IP