I have a PHP project, and I need to hide the .php extension in the URL with .htaccess
. I can already do that with this .htaccess
file
# Run Php without filename extension
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php
# Return 404 if original request is .php
RewriteCond %{THE_REQUEST} "^[^ ]* .*?\.php[? ].*$"
RewriteRule .* - [L,R=404]
now, I need to allow the .php extention in the index.php inside the folder called php which is inside a folder called server (myproject/server/php/index.php).
how can I do that?
Add the below lines to the .htaccess file.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [NC,L]
For more details, please the following the link.
https://www.plothost.com/kb/how-to-remove-php-html-extensions-with-htaccess/
Try with below rule,
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/index.php
RewriteRule ^(.*)$ $1.php [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.