问题描述
我想从http://fubar.com/subpage.PHP?pageId=99
开始
然后结束另一个域http://newdomain.org/fubar/99
这是我的.htaccess顶部的内容
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} /subpage.PHP\?pageId=(.*)$
RewriteRule ^ http://newdomain.org/fubar/?%2 [R=301,L,NE]
这就是我所得到的。
from
http://fubar.com/subpage.PHP?pageId=99
to
http://newdomain.org/fubar/?pageId=99
我不了解?
中RewriteRule末尾的?%2
。我希望将其删除,但最终只得到http://newdomain.org/fubar/
奖金问题,经过这样的测试后,如何重新设置?遇到问题时,我总是不得不切换浏览器和隐身模式。
解决方法
THE_REQUEST
变量表示Apache从您的浏览器收到的原始请求,并且在执行其他重写指令后不会被覆盖。此变量的示例值为GET /index.php?id=123 HTTP/1.1
。这意味着您要捕获查询参数pageId
的正则表达式不正确,除了%2
始终为空,因为您仅捕获一个值。
您可以使用以下规则:
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} /subpage\.php\?pageId=([^&\s]*) [NC]
RewriteRule ^ http://newdomain.org/fubar/%1? [R=301,L,NE]
最后, ?
会删除先前的查询字符串,该字符串会自动转发到新的URL。