regex - Apache 重定向正则表达式 : match something that is not following something

标签 regex apache pcre

什么正则表达式应该代表“所有不跟在‘index.php’之后的东西都应该指向‘index.php/$1’”?

例如,“http://mysite/moo”应该指向“http://index.php/moo”,而“http://index.php/moo”不应该。

我目前正在使用 PCRE 正则表达式(Apache 文档说应该在此处使用 PCRE)无效:RedirectMatch (?<=index\.php)(\/.+) /index.php/$1 .

什么是正确的?

UPD:重点是只使用 mod_alias,省略 mod_rewrite

最佳答案

您可以使用 RedirectCond具有不匹配的模式(“!”前缀)。尝试:

RewriteCond %{REQUEST_URI} !^/index.php
RewriteRule (.*) index.php/$1

或者:

RewriteCond $1 !^/?index.php
RewriteRule (.*) index.php/$1

关于regex - Apache 重定向正则表达式 : match something that is not following something,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7084048/

相关文章:

Python 正则表达式(在一个字符串中搜索多个值)

javascript - 匹配多个值并将重复值替换为一个值

Apache 强制 SSL

php - 使用 htaccess 忽略链接的某些部分

用于查找标记 ID 的正则表达式

ruby-on-rails-3 - 如何重新编译 nginx

php - 编译失败 : POSIX collating elements are not supported

javascript - 手动解析此正则表达式的步骤/([.*+?^=!:${}()|\]\\])/g

c# - 找到 RegEx 匹配然后提取

apache - 使用 mod_include 和 mod_proxy 包含远程 .shtml 文件时出现乱码