重定向整个域及其相应的URL和查询字符串(一个除外)

时间:2019-02-07 13:39:19

标签: .htaccess

.htaccess中有一条规则,该规则将整个域及其URL和查询字符串重定向到一个新域。但是,我想从中排除一个URL。我仍要重定向该URL,以从中删除查询字符串。因此,对于https://www.test1.com/search?type=content,应将其重定向到https://www.test.com/search,以除去查询字符串,但对于其余的URL,以下内容就可以了。

  # Redirect users from test1.com to https://www.test.com
  RewriteCond %{HTTP_HOST} ^(www.)test1\.com$ [NC]
  RewriteRule ^ https://www.test.com%{REQUEST_URI} [R=301,L]

1 个答案:

答案 0 :(得分:0)

您可以使用此:

#redirect and discard querystring from /search?type=content
RewriteCond ℅{THE_REQUEST} /search/?\?type=content [NC]
RewriteRule ^ https://www.test.com%{REQUEST_URI}? [R=301,L]
# Redirect users from test1.com to https://www.test.com
RewriteCond %{HTTP_HOST} ^(www.)test1\.com$ [NC]
RewriteRule ^ https://www.test.com%{REQUEST_URI} [R=301,L]