Apache重定向正则表达式:匹配不遵循某些内容的东西

时间:2011-08-16 19:45:07

标签: regex apache pcre

regexp应该代表什么“不遵循的一切'index.php'应该指向'index.php / $ 1'”?

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

我目前正在使用PCRE regexp(Apache文档说这里应该使用PCRE)不起作用:RedirectMatch (?<=index\.php)(\/.+) /index.php/$1

什么是正确的?

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

3 个答案:

答案 0 :(得分:3)

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

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

或者:

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

答案 1 :(得分:2)

也许:

^/?(?!index\.php)(.+)

即。否定前瞻

答案 2 :(得分:0)

我只尝试过简单的重定向到静态网站(工作):

RedirectMatch   ^(?!/index\.htm$).*$    /index.htm

基于此,以下内容可能会对您有所帮助(未尝试过):

RedirectMatch   ^(?!/index\.php$)(.*)$    /index.php$1

See also: Mastering Lookahead and Lookbehind

相关问题