Reputation: 4076
I am attempting to rewrite the URLs on my site from .php to .html and I have some other rules that are interfering with what I would like to do.
The code below shows all the rules working but I have some flat PHP pages that I would like to turn into .html pages. An example would be history.php to history.html.
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
##Vendor Pages
RewriteRule ^([^/]+)/([^/]+)/([^.]+)\.html?$ vendors2.php?vendorslug=$3&locationslug=$1&categoryslug=$2 [L,QSA,NC]
##Listing Pages
RewriteRule ^([^/]+)/([^.]+)\.html?$ listings.php?locationslug=$1&categoryslug=$2 [L,QSA,NC]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !^(.*/)?history\.html$ [NC]
RewriteRule ^([^/.]+)\.html?$ $1.php [L,NC]
##Locations Pages
RewriteRule ^([^/.]+)\.html?$ locations.php?locationslug=$1&Submit=Submit [L,QSA,NC]
Currently, the code appears to be confused with other rules because it is attempting to return the page as a "Location Page" because of the rules.
There are several pages that I need to turn into .html (history.php, news.php, maps.php, resources.php, trivia.php and others).
Any constructive help is appreciated.
Upvotes: 0
Views: 50
Reputation: 7074
It's possible that you're simply not matching the RewriteCond's. Your RewriteCond
to check that the file exists is likely being interpreted as, say, "is /home/username/public_html/history.html.php
a file?", which will fail.
I would suggest that rather than include several RewriteCond
's before your rule, you could replace it with a single RewriteRule
, before your ##Locations Pages
. Something like the following:
RewriteRule (history|news|maps|resources)\.html $1.php [L]
Note that this could make for a loooong line if you have a lot of entries, so you could just split it into several rules.
If you're looking for the request being in the "root":
RewriteRule ^(history|news|maps|resources)\.html$ $1.php [L]
Upvotes: 1