简体   繁体   English

htaccess删除php扩展名(一个特定的文件夹除外)

[英]htaccess remove php extension except for one specific folder

I have a PHP project, and I need to hide the .php extension in the URL with .htaccess . 我有一个PHP项目,我需要使用.htaccess在URL中隐藏.php扩展名。 I can already do that with this .htaccess file 我已经可以使用此.htaccess文件执行此操作

# 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). 现在,我需要在名为php的文件夹中的index.php中允许.php扩展,该文件夹位于名为server(myproject / server / php / index.php)的文件夹中。

how can I do that? 我怎样才能做到这一点?

Add the below lines to the .htaccess file. 将以下行添加到.htaccess文件。

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/ 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]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM