I have a site that's built with PHP and I'm using the .htaccess
file to remove the .php
extension.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
This works fine and means that I can access /file.php
by doing /file
. However if I put a trailing slash at the end of the URL I get a 404 error. I've tried quite a few things but I can't get it work. Does anyone know what I'm doing wrong?
You can use this .htaccess:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
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.