Forum Moderators: phranque

Message Too Old, No Replies

Remove .php extension with mod-rewrite

         

terrybarnes

8:29 pm on Feb 28, 2009 (gmt 0)

10+ Year Member



I have my pages set up like so:

about.php
contact.php
section/page1.php

etc etc but I would like it so you simply had to type in the following

/about
/contact
/section/page1

etc etc

I really haven't got a clue when it comes to this kind of programming and looking around the web, and this forum it all seems like jargon to my design based mind!

I'm sure this is a very simple request but can anyone help? Any advice would be very much appreciated.

g1smd

8:38 pm on Feb 28, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You'll need a
rewrite
to connect the URL request to the internal server filename. Use a
RewriteRule
for this.

It uses very similar syntax to a redirect; but for a rewrite the target should not contain a domain name.

Use [L] at the end of the rule. Post your best effort code here with details of what problems you are having.

You'll also need to update the URLs in the links on your pages to use the new format as it is links that 'define' URLs.

You will also need to set up a conditional 301 redirect such that if anyone directly requests a URL that ends with .php that they are redirected to make a new request for the new URL. Failure to implement the 301 redirect will mean that both versions of the URL will return Duplicate Content - and that is bad. The redirect should also force www for those URLs at the same time.

jdMorgan

10:17 pm on Feb 28, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



See this recent thread: Cruft Free URLs for Dummies [webmasterworld.com]

Jim