Apache Mod重写链接并查询到另一个子域
我有一个查询字符串链接,我想将其重写到另一个子域。我尝试了以下方法:Apache Mod重写链接并查询到另一个子域,apache,mod-rewrite,Apache,Mod Rewrite,我有一个查询字符串链接,我想将其重写到另一个子域。我尝试了以下方法: RewriteRule ^/forum/viewtopic.php(.*)$ http://sub2.domain.com/viewtopic.php$1 [R=301,L,QSA] 以及: RewriteCond %{QUERY_STRING} RewriteRule ^forum/viewtopic.php(.*) http://sub2.domain.com/forum/viewtopic.php?%1 你可以想象
RewriteRule ^/forum/viewtopic.php(.*)$ http://sub2.domain.com/viewtopic.php$1 [R=301,L,QSA]
以及:
RewriteCond %{QUERY_STRING}
RewriteRule ^forum/viewtopic.php(.*) http://sub2.domain.com/forum/viewtopic.php?%1
你可以想象,它没有飞。我看到的大多数示例都涉及到指定实际的查询字符串,但是,我的链接传递了几个变量,并且不总是以相同的顺序传递。是否可以基于viewtopic.php重写URL?(任何后续内容)
原始链接:
sub1.domain.com/forum/viewtopic.php?p=123&sid=c75edda9
sub1.domain.com/forum/viewtopic.phpt=321&start=0&postdays=0&sid=6e97b05
sub1.domain.com/forum/viewtopic.php?t=45&view=next&sid=f799
sub2.domain.com/forum/viewtopic.php?p=123&sid=c75edda9
sub2.domain.com/forum/viewtopic.php?t=321&start=0&postdays=0&sid=6e97b05
sub2.domain.com/forum/viewtopic.php?t=45&view=next&sid=f799
新链接:
sub1.domain.com/forum/viewtopic.php?p=123&sid=c75edda9
sub1.domain.com/forum/viewtopic.phpt=321&start=0&postdays=0&sid=6e97b05
sub1.domain.com/forum/viewtopic.php?t=45&view=next&sid=f799
sub2.domain.com/forum/viewtopic.php?p=123&sid=c75edda9
sub2.domain.com/forum/viewtopic.php?t=321&start=0&postdays=0&sid=6e97b05
sub2.domain.com/forum/viewtopic.php?t=45&view=next&sid=f799
简单到:
RewriteRule ^forum/viewtopic.php$ http://sub2.domain.com/forum/viewtopic.php [R=301, L]
不需要任何[QSA],因为您不修改查询字符串。我修改了规则,但仍然无法执行。它转到新页面,但去掉查询字符串
code
RewriteRule^forum/viewtopic\.php$sub2.domain.com/forum/viewtopic.php?[R,L]code
松开?
,否则将用空字符串替换查询字符串。此规则有效code
RewriteRule^forum/viewtopic.php(.*$[R,L]code