问题原文
原帖链接 · Pasakgroup · CC BY-SA 4.0
I want to redirect all pages of SiteA to homepage of SiteB.
I used this code in SiteA's .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(.*)$ https://SiteB.tld/ [R=301,L]
</IfModule>
The code works perfectly, but not for URLs with Question Mark, such as
https://SiteA.tld/?action=dayview&calendar=1&year=2000&month=01&day=01
This pages will get 404 Not Found and wouldn't redirect to SiteB's hompage.
What changes should I make in the Redirection code?
已采纳解答
原帖链接 · Stephen Ostermiller · CC BY-SA 4.0
You should add the "query string discard" or QSD flag to your rewrite rule:
RewriteRule ^(.*)$ https://SiteB.tld/ [R=301,QSD,L]
From the documentation:
When the requested URI contains a query string, and the target URI does not, the default behavior of RewriteRule is to copy that query string to the target URI. Using the
[QSD]flag causes the query string to be discarded.This flag is available in version 2.4.0 and later.
Using
[QSD]and[QSA]together will result in[QSD]taking precedence.If the target URI has a query string, the default behavior will be observed - that is, the original query string will be discarded and replaced with the query string in the
RewriteRuletarget URI.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
