regex - 重写规则从 Regex 中的 (.*) 中排除某些字符串

标签 regex .htaccess

我目前有以下 htaccess 重写规则:

RewriteRule    (.*) index.php/$1 [L]

如何让它排除 2 个特定的字符串,例如:'template' 和 'image'?

我看了其他帖子,但我不清楚。

最佳答案

你可以做一个否定的重写条件

像这样:

RewriteCond %{REQUEST_URI} !^/(template|image)
RewriteRule (.*) index.php/$1 [L]

这实际上不会重写任何指向图像和模板文件夹中内容的 url。

关于regex - 重写规则从 Regex 中的 (.*) 中排除某些字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11172642/

相关文章:

angularjs - magento 2 REST API 调用期间出现 400 错误请求

.htaccess - Azure 网关 https 后端池和 htaccess 重定向循环

JAVASCRIPT:正则表达式查找多个 | 之间的字符|

regex - 从 R 中的字符串中删除反斜杠

java - 滥用 ragel,可能需要新的方法/工具

javascript - 使用反向引用的最佳方法是什么?

performance - .htaccess mod_rewrite 性能

php - 使用 .htaccess 重定向/投票到/vote.php?vote=1

regex - R正则表达式问题

.htaccess 强制 404 并阻止目录列表