Rewrite domain.com/page.php to domain.com/page/

Discussion in 'Apache' started by Kerosene, Jul 21, 2007.

  1. #1
    Possibly one of the most basic rewrite questions there is.... I'm embarrassed I don't know how to do it :eek::p

    My site has urls like:
    www.domain.com/page.php

    I'd like to change them to:
    www.domain.com/page/

    and have it work with AND without trailing slash.

    How is it done?
     
    Kerosene, Jul 21, 2007 IP
  2. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #2
    Options +FollowSymLinks +Indexes
    RewriteEngine on
    RewriteBase /
    RewriteRule ^([^.]+)/$ $1.php [L]
    RewriteRule ^([^.]+)$ $1.php [L]
     
    Nintendo, Jul 21, 2007 IP
    Kerosene and onedollar like this.
  3. Kerosene

    Kerosene Alpha & Omega™ Staff

    Messages:
    11,366
    Likes Received:
    575
    Best Answers:
    4
    Trophy Points:
    385
    #3
    You da King!

    Thanks :)

    EDIT: Actually... there's a bit of a problem. I've tried to 301 the old php urls that Google has indexed, but I'm getting an error from Firefox "Firefox has detected that the server is redirecting the request for this address in a way that will never complete."

    I can see why it's doing this, but I don't know how to fix it.

    Options +FollowSymLinks
    RewriteEngine On
    
    RewriteCond %{HTTP_HOST} ^domain.com$ [OR]
    RewriteCond %{HTTP_HOST} www.domain.com$ [OR]
    RewriteCond %{HTTP_HOST} ^domain.com.au$
    RewriteRule ^(.*)$ http://www.domain.com.au/$1 [R=301,L]
    
    RewriteRule ^([^.]+)/$ $1.php [L]
    RewriteRule ^([^.]+)$ $1.php [L]
    
    Redirect 301 /page1.php http://www.domain.com.au/page1/
    Code (markup):
     
    Kerosene, Jul 21, 2007 IP
  4. Kerosene

    Kerosene Alpha & Omega™ Staff

    Messages:
    11,366
    Likes Received:
    575
    Best Answers:
    4
    Trophy Points:
    385
    #4
    Can anyone help with the 301s?

    At the moment Google will see the 'new' domain.com/page1/ url as duplicate content of domain.com/page1.php.

    I need to 301 the indexed php pages to domain.com/page1/ etc
    There's only about 10 pages I need to 301, so I can enter them manually - if I knew how to do it.

    Anyone?
     
    Kerosene, Jul 22, 2007 IP
  5. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #5
    It's making apache go bonkers. No, it's domain.com/page1/. No it's not, it's domain.com/page1.php. No it's not.... That's why mod_rewrite should be done before search engines get them, and so you don't have old URLs indexed.
     
    Nintendo, Jul 23, 2007 IP