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

标签 php .htaccess url

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

相关文章:

php - 将 Laravel 4 密码重置 Controller 升级到 Laravel 5

PHP MySQL 查询问题/帮助 - 连接表

php - 登录 session 未按预期工作

html - 如何将 mime 类型添加到 htaccess 文件?

php - LARAVEL 4 解决方案动态 SEO URLs 通缉

python - Django 发送带有链接的电子邮件

php - 无法使用 PHP 和 Nginx 让 Zorba 在 Windows 7 上工作

php - 使用 .htaccess 将 PHP 错误记录到 xampp 本地主机中的文件中

.htaccess - 模式中的 mod_rewrite RewriteRule 反向引用使用

apache - 使用mod_rewrite的不区分大小写的URL