使用htaccess将查询字符串附加到URL

时间:2014-06-10 22:29:38

标签: .htaccess mod-rewrite redirect url-rewriting pretty-urls

我需要将查询字符串附加到特定网址以进行广告系列跟踪/表单提交。例如,我需要http://domain.com/page/重定向到http://domain.com/page/?Campaign_ID=123456

当我尝试访问domain.com/page时,我试图设置它的方式是给我一个重定向循环错误消息:

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
Redirect 301 /page http://domain.com/page/?Campaign_ID=1234656

我也尝试使用RewriteRule,这也是给我循环消息:

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^page$ http://domain.com/page/?Campaign_ID=1234656 [L,NE,R=301]

对不起,如果这个问题已在这里得到解答了。我搜索了一段时间但无法找到它,所以请不要对我大喊大叫。我确实试图自己找到它。谢谢!

2 个答案:

答案 0 :(得分:1)

尝试:

RewriteEngine On
RewriteBase /

RewriteRule ^index\.php$ - [L]

RewriteCond %{QUERY_STRING} ^$
RewriteRule ^page/?$ http://domain.com/page/?Campaign_ID=1234656 [L,NE,R=301]

答案 1 :(得分:0)

尝试一下:

RewriteCond %{REQUEST_URI} ^(/page/)(.*)$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1?Campaign_ID=1234656 [L,R=301]