我的 .htaccess
规则从 URL 中删除所有 .html
和 .php
扩展名。
但是我需要从这个规则中排除一个特定的 .php
文件,例如文件 mailscript/sendmail.php
在我现在拥有的当前规则配置下,这怎么可能?
.htaccess
AddType text/html .shtml
AddHandler server-parsed .shtml
Options Indexes FollowSymLinks Includes
AddHandler server-parsed .html .htm
RewriteEngine on
RewriteCond %{THE_REQUEST} /([^.]+)\.html [NC]
RewriteRule ^ /%1 [NC,L,R]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ %{REQUEST_URI}.html [NC,L]
RewriteCond %{THE_REQUEST} /([^.]+)\.php [NC]
RewriteRule ^ /%1 [NC,L,R]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [NC,L]
我尝试应用RewriteRule ^sendmail\.php$ [L]
基于on this answer但它不适用于我当前的规则。
最佳答案
您可以添加此规则以跳过 sendmail.php
:
RewriteRule (?:^|/)sendmail\.php$ - [L,NC]
将此规则添加到 RewriteEngine on
行的正下方。
关于php - 删除 php/html 扩展名并从规则中排除一个特定文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50456367/