使用 aRewriteCond
来匹配查询字符串的内容(因为它们不是在RewriteRule
指令中读取的,swfTitle=sometitle.swf
您folder1/folder3
可以folder1/folder2
在moviefolder
.
这将使用正则表达式模式([^&]+)
将所有内容匹配到下一个&
(表示另一个查询参数)。
# Capture everything after folder2 into %1
RewriteCond %{QUERY_STRING} moviefolder=folder1/folder2([^&]+) [NC]
# Capture everything in the swfTitle param into %2
# Both conditions must be matched...
RewriteCond %{QUERY_STRING} swfTitle=([^&]+) [NC]
# Then silently rewrite mypage.php to substitute folder3,
# and pass in the original swfTitle captured above
RewriteRule ^mypage\.php$ mypage.php?moviefolder=folder1/folder3%1&swfTitle=%2 [L]
希望您不会出现重写循环,因为重写folder1/folder3
后的第二次将不匹配。 [NC]
允许不区分大小写的匹配。
我确实设法在http://htaccess.madewithlove.be/上成功地测试了这个,使用示例输入:
http://example.com/mypage.php?swfTitle=thetitle.swf&moviefolder=folder1/folder2/thing
---> http://example.com/mypage.php?moviefolder=folder1/folder3/thing&swfTitle=thetitle.swf
http://example.com/mypage.php?moviefolder=folder1/folder2/thing999zzz&swfTitle=thetitle.swf
---> http://example.com/mypage.php?moviefolder=folder1/folder3/thing999zzz&swfTitle=thetitle.swf