代码之家  ›  专栏  ›  技术社区  ›  Cadmos

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

  •  3
  • Cadmos  · 技术社区  · 6 年前

    我的 .htaccess 规则全部删除 .html .php 从URL扩展。

    但是我需要排除一个特定的 php 来自此规则的文件,例如 mailscript/sendmail.php

    在我现有的规则配置中,这是如何实现的?

    .h访问

    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 但这不符合我目前的规则。

    1 回复  |  直到 6 年前
        1
  •  2
  •   anubhava    6 年前

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

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

    在下面添加此规则 RewriteEngine on 线。