在子目录之外的URL中删除.php扩展名

霍萨姆·艾尔扎(Hosam Elzagh)

您好,我用下面的代码从.htaccess index.php --------索引中的URL中删除扩展名.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

阿米特·维玛(Amit Verma)

您可以使用以下内容:

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]

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章