Forum Moderators: phranque

Message Too Old, No Replies

ReWrite Help,

Help with ReWriting

         

codyadam

6:34 pm on Feb 13, 2009 (gmt 0)

10+ Year Member



Hi Everyone, i'm new to this forum and the world of ReWrite. I have a website which i would like to tidy up the links in the address bar, some examples are below:

http://www.example.com/New/privacy-policy.php
http://www.example.com/New/web-hosting.php
http://www.example.com/New/home.php

i'd like to get rid of the .php and replace it with /. so it would look like this:

http://www.example.com/New/privacy-policy/
http://www.example.com/New/web-hosting/
http://www.example.com/New/home/

is that possible? if so how is it done? here is what i was given by someone:

RewriteBase /New/

RewriteRule ^([a-z]+)$ $1/ [R]
RewriteRule ^([a-z]+)/$ /$1\.php

but it doesn't seem to work.

Please help.

Many Thanks In Advance
Cody

jdMorgan

7:57 pm on Feb 13, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Cody, and welcome to WebmasterWorld!

To get started, take a look at this recent thread: Cruft Free URLs [webmasterworld.com].

Be aware of two things: First, you must edit your HTML pages --or the script that produces those HTML pages-- so that the ".php" no longer appears in linked URLs on your pages. Then you use mod_rewrite to "re-connect" those URLs, when requested from your server, to the .php script that produces the pages associated with your now-extensionless URL. The process requires two steps, and cannot be correctly done with mod_rewrite alone: Take the ".php" off the links on your pages, then use mod_rewrite to add ".php" back on to the internal filepaths associated with those URLs.

Second, you will need to check for "URL collisions" with existing directories if you use a slash on the end of your new extensionless URLs. So consider whether you really need that trailing slash, and leave it off if not.

Post specific questions back here.

Jim

codyadam

8:30 pm on Feb 13, 2009 (gmt 0)

10+ Year Member



Hi Jim, Thanks for the information, i have considered everything you have said, and decided against putting the trailing slash on to save any problems in the future should i need to add any directories.

I'll try out what i have learned and get back to you if i have any problems.

Cody