简体   繁体   English

删除php / html扩展并从规则中排除一个特定文件

[英]Remove php/html extensions and exclude one specific file from the rules

My .htaccess rules remove all .html and .php extensions from URL. 我的.htaccess规则从URL中删除所有.html.php扩展名。

However I need to exclude one specific .php file from this rule, for example the file mailscript/sendmail.php 但是,我需要从此规则中排除一个特定的.php文件,例如文件mailscript/sendmail.php

How would that be possible on the current rules configuration I have now ? 我现在的规则配置怎么可能呢?

.htaccess 的.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]

I tried to apply RewriteRule ^sendmail\\.php$ [L] based on this answer but it did not work with my current rules. 我试图根据这个答案应用RewriteRule ^sendmail\\.php$ [L] 但它不符合我现在的规则。

You can add this rule to skip sendmail.php : 您可以添加此规则以跳过sendmail.php

RewriteRule (?:^|/)sendmail\.php$ - [L,NC]

Add this rule just below RewriteEngine on line. RewriteEngine on下方添加此规则。

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

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