【问题标题】:Remove php/html extensions and exclude one specific file from the rules删除 php/html 扩展名并从规则中排除一个特定文件
【发布时间】:2018-10-31 13:18:00
【问题描述】:

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

我尝试基于on this answer 应用RewriteRule ^sendmail\.php$ [L],但它不适用于我当前的规则。

【问题讨论】:

    标签: php .htaccess url


    【解决方案1】:

    您可以添加此规则跳过sendmail.php

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

    RewriteEngine on 行下方添加此规则。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-29
      • 2017-09-09
      • 1970-01-01
      • 2023-04-05
      • 1970-01-01
      • 2017-12-13
      相关资源
      最近更新 更多