htaccess添加参数HOST

时间:2017-12-22 17:43:35

标签: .htaccess

如何为给定域的每次调用添加参数?

示例:

www.domain1.com it always has to be added at the end ?test1=abc
www.domain2.com it always has to be added at the end ?test1=def

我添加了代码:

RewriteCond %{HTTP_HOST} ^domain1\.com$ [NC]
RewriteRule ^ %{REQUEST_URI}?test1=abc [L,R=301,QSA]
RewriteCond %{HTTP_HOST} ^domain2\.com$ [NC]
RewriteRule ^ %{REQUEST_URI}?test1=def [L,R=301,QSA]

添加了参数,但有一个循环:

domain1.com/?test1=abc&?test1=abc&?test1=abc&?test1=abc&?test1=abc&
domain2.com/?test1=def&?test1=def&?test1=def&?test1=def&?test1=def&
非常感谢你的帮助

1 个答案:

答案 0 :(得分:0)

您应添加RewriteCond以测试包含test1查询字符串的URI:

RewriteCond %{HTTP_HOST} ^domain1\.com$ [NC]
RewriteCond %{QUERY_STRING} !test1=
RewriteRule ^ %{REQUEST_URI}?test1=abc [L,R=301,QSA]

RewriteCond %{HTTP_HOST} ^domain2\.com$ [NC]
RewriteCond %{QUERY_STRING} !test1=
RewriteRule ^ %{REQUEST_URI}?test1=def [L,R=301,QSA]