将查询字符串从站点根目录重定向到子域站点根目录

时间:2015-09-29 16:06:44

标签: regex apache .htaccess redirect url-rewriting

我正在尝试重定向

http://example.com/?download_invoice=true&attendee_id=28916&r_id=504-55803a183a0cf

http://secure.example.com/?download_invoice=true&attendee_id=28916&r_id=504-55803a183a0cf

但没有运气。我可以使用以下语法将查询字符串从子目录重定向:

RewriteCond %{REQUEST_URI} ^/sub-directory/$
RewriteRule ^.*$ http://secure.example.com/sub-directory/ [L,R=301]

但无法弄清楚如何从站点根目录执行此操作。任何帮助都会非常感谢,提前谢谢!

1 个答案:

答案 0 :(得分:0)

您需要匹配RewriteCond中的主机名和^$中的RewriteRule模式:

RewriteCond %{QUERY_STRING} .
RewriteCond %{HTTP_HOST} ^(?:www\.)?(example\.com)$
RewriteRule ^/?$ http://secure.%1/ [L,R=301]

QUERY_STRING会自动转发到目标网址。