1

Flash 电影是基于mypage.php. mypage.php嵌入了 Flash 播放器。链接看起来像mypage.php?moviefolder=folder1/folder2&swfTitle=sometitle.swfmypage.php在每次链接点击时解析(每个 href)。 Folder2总是相同的,但是movieTitle.swf是动态的。有时子文件夹会被称为 ( folder2/subfolder2/sometitle.swf)。

mod_rewrite 可以允许查询字符串反映文件夹 2,而是静默服务folder3以及偶尔的子文件夹吗?我会将所有文件放在文件夹 3 中。目标是让用户不知道 swfs 在哪里。再次提前感谢!

4

1 回答 1

1

使用 aRewriteCond来匹配查询字符串的内容(因为它们不是在RewriteRule指令中读取的,swfTitle=sometitle.swffolder1/folder3可以folder1/folder2moviefolder.

这将使用正则表达式模式([^&]+)将所有内容匹配到下一个&(表示另一个查询参数)。

# 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
于 2013-01-31T02:54:27.887 回答