First to say, sorry if I'm doubleposting, but I didn't find a solution to this one.
I'm trying to rewrite my urls so that, whene I enter somepage.html it serves me somepage.php but ONLY if somepage.html doesn't exist. Anyone can help? Thanks
First to say, sorry if I'm doubleposting, but I didn't find a solution to this one.
I'm trying to rewrite my urls so that, whene I enter somepage.html it serves me somepage.php but ONLY if somepage.html doesn't exist. Anyone can help? Thanks
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^.]+)\.html$ $1.php [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([A-Za-z0-9-]+)\.html$ $1.php [L,R=301]
I had the same issue, this was my solution.
This will check to see if there is a HTML file present, if not it will use PHP - ideal if you have migrated your website to PHP and are concerned about any 3rd party links to HTML pages
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)\.html$ $1.php [R=301,L
]