您好我使用下面的代码从.htaccess中的url中删除扩展名.php index.php --------索引,它工作正常。
请协助我停止删除子目录中的.php扩展名,例如:www.example.com/cp/index
而不是:www.example.com/cp/index.php
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.php
RewriteRule ^/?(.*)\.php$ /$1 [NC,L,QSA,R=301]
以下不起作用:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} ^/([^/]+)/?
RewriteCond %{DOCUMENT_ROOT}/%1.php -f
RewriteRule ^(.*)$ %1.php [L]
我可以在异常目录中调用一个特定的cp
答案 0 :(得分:2)
您可以使用以下内容:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
#####exclude /cp folder####
RewriteCond %{REQUEST_URI} !^/cp
#################
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /((?!cp)[^.]+)\.php
RewriteRule ^/?(.*)\.php$ /$1 [NC,L,QSA,R=301]