将所有网址重写为新域名并添加额外参数

时间:2016-12-27 19:34:18

标签: apache .htaccess mod-rewrite url-rewriting

1 个答案:

答案 0 :(得分:1)

所以,基本上你需要在任何可能构造的URL的查询字符串中添加pa=va

RewriteEngine on
RewriteBase /

# Check if the host matches old.io,
# You might want to add www\. to that.
RewriteCond %{HTTP_HOST} ^old\.io

# Rewrite URLs with empty querystring
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(.*)$ http://new.com/$1?pa=va [L,R]

# Rewrite URLs with non-empty querystring    
RewriteCond %{QUERY_STRING} ^.+$
RewriteRule ^(.*)$ http://new.com/$1?pa=va&%{QUERY_STRING} [L,R]

请注意,锚点哈希部分需要在查询字符串之后

如果您愿意,可以test it online