I m playing with apache rewrite_mod (Apache/2.2.17 Win32) and encounter very weird behave of rewriteRule.
My script primarily rewrite infinite filter parameters named f1 .. f<infinity>
from nice url and in loop adding them as query variables, add path as query, and page number.
It works flawlessly, but if I add one another rule (last rule in script)
RewriteRule ^(.+).html$ /index.php?path=$1.html [QSA]
对于其他情况,它会改变剧本开头的重写执行。
Input URL:
http://testing.loc/some/thing/index0-f1-nice-cars-f2-planes-f3-karts-f4-bike.html
期望在所有重写后产生 PHP :
$_SERVER[QUERY_STRING] => path=some/thing/&page=0&f1=nice-cars&f2=planes&f3=karts&f4=bike
$_SERVER[SCRIPT_NAME] => /index.php
脚本看起来像这样( 下一部分功能完美无缺) :
# from: some/thing/index0-f1-nice-cars-f2-planes-f3-karts-f4-bike.html
# to: some/thing/index0.html?f=-f1-nice-cars-f2-planes-f3-karts-f4-bike
RewriteRule ^(.*/?index[0-9]*)((?:-f[0-9]+-.+?)+).html$ /$1.html?f=$2 [QSA]
# from: some/thing/index0.html?f=-f1-nice-cars-f2-planes-f3-karts-f4-bike
# to index.php?path=some/thing/&page=0&f=-f1-nice-cars-f2-planes-f3-karts-f4-bike
# ( $1 ) ( $2 )
RewriteRule ^(.+/{0,1})index([0-9]*).html$ /index.php?path=$1&page=$2 [QSA]
# while in f is something like "f1-nice-cars" (for example)
# remove "f1-nice-cars" from f and add as query "f1=nice-cars"
# (%1) ( %2 ) ( %3)( %4 )
RewriteCond %{QUERY_STRING} ^(.*)&f=-(f[0-9]+)-(.+?)((?:-f[0-9]+-.+)*)$
RewriteRule ^index.php$ /index.php?%1&%2=%3&f=%4 [L]
# remove empty "f=" from query
RewriteCond %{QUERY_STRING} ^(.*)&f=$
RewriteRule ^index.php$ /index.php?%1
在这里,在规则是骨灰之后:
index.php?path=some/thing/&page=0&f1=nice-cars&f2=planes&f3=karts&f4=bike
没有下一条脚本规则, 下一条规则是完全实用的 坚固> 。 但是如果我加上它, 这条规则本身没有作用, 但是重写_ mod 给脚本开头的下一条添加更多内容 。
# rewrite rule for other paths without filters
RewriteRule ^(.+).html$ /index.php?path=$1.html [QSA]
实际上运行后所有的脚本结果是:
index.php?path=/some/thing/index0.html/some/thing/index0&f1=nice-cars&f2=planes&f3=karts&f4=bike