views:

34

answers:

1

I have a website with a CMS that uses mod_rewrite to make URLs look cleaner. Previously, the clean URLs had the extension .htm, but I want to transition this to them appearing as fake subdirectories, IE:

http://www.example.com/pagename/

I have two rewrite rules in place to rewrite both the old scheme and the potential new one:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+).htm$ index.php?page=$1 [QSA]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ index.php?page=$1 [QSA]

My problem is that the rule I tried to use to redirect old URLs to new ones does nothing.

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+).htm$ $1/ [R=302,NC,QSA]
+1  A: 

You can not use two rules with the same pattern as only the first of them will be applied. Try to replace your “rewrite” rule with the new “redirect” rule to get the old URLs redirected instead of just rewritten:

# redirect foo.htm to foo/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)\.htm$ $1/ [R=301,NC]
# rewrite foo/ to index.php?page=foo
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ index.php?page=$1 [QSA]
Gumbo
Thanks. For the record, the rule I used:RewriteRule ^(.+)\.htm$ http://www.example.com/$1/ [R,NC,QSA]
Simon Brown