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!
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]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.