Forum Moderators: phranque

Message Too Old, No Replies

Mod_Rewrite adding a slash to my url

Needs to be sorted asap

         

richiebman

4:56 pm on Aug 24, 2004 (gmt 0)

10+ Year Member



Hello. I'm new to this mod_rewrite stuff, but am finding it fascinating......if not infuriating - as you may have read from my below posts. I also know jack about refining the code I've got so I apologise.
I have this in the root .htaccess of a friends website:

AddHandler cgi-script .html
DirectoryIndex home.html
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} !/$
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*) $1\.html [L]
RewriteRule ^(.*)\.shtml $1 [R]
RewriteRule ^(.*)\.php $1 [R]

Why the .php and .shtml rules you may ask? Well the site started out as .shtml, then I learnt .php, then I learnt mod_rewrite. I want clean urls and on my newly installed apache web server (for home testing), the above is great. If a user had a bookmark with a .php or .shtml end to it, it would redirect to the (php parsed) html clean urls. As I said the above code is fine at home and even on my web hosts server.....until you add a .php or .shtml extension to the clean extension free url.....when it decides to add extra slash. So:

www.example.co.uk/rbarn

when .php added

www.example.co.uk/rbarn.php

hit enter and becomes

www.example.co.uk//rbarn

It's so close, but not good enough, because when you link to other pages in different directories it chucks up a file not found error.

So what do I have to do to

RewriteRule ^(.*)\.shtml $1 [R]
RewriteRule ^(.*)\.php $1 [R]

to sort out this problem. Perhaps something to do with the (.*)?
Many thanks,

R

[edited by: jdMorgan at 6:27 pm (utc) on Aug. 24, 2004]
[edit reason] Removed specific URLs per TOS [/edit]

richiebman

5:28 pm on Aug 24, 2004 (gmt 0)

10+ Year Member



Figured it out.

Changed the last 3 lines to

RewriteRule ^(.+)$ $1\.html [L]
RewriteRule ^([^/]+)\.shtml$ /$1 [R]
RewriteRule ^([^/]+)\.php$ /$1 [R]

So I thank JDMorgan for his reply to a previous post I have just come across.

R