Reputation: 125
I am attempting to remove .html and .php extensions from my website's URLs. I have been suggested to use the following code:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
This indeed works, however it will only work for one extension at a time. So I can either have .html removed, or .php removed from the URL. I need to have both removed simultaneously. Someone suggested I just rename all my .html files to .php, however this will not work for me. Previously, I was able to remove both extensions purely using .htaccess, but am unable to find the solution that I used before.
I also tried this code and it only removes the extension for .html:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
RewriteRule ^([^\.]+)$ $1.php [NC,L]
What code do I need to make this work?
Thank you in advance for your assistance!
Upvotes: 1
Views: 62
Reputation: 26153
if php files have more prioritet, than html ones, swap groups of lines
RewriteEngine On
# if exist file.html
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
# if exist file.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
Upvotes: 1