Use htaccess to append a query string to URL

2019-08-03 09:20发布

I need to append query strings to certain URLs for campaign tracking/form submission. so for instance, i need http://domain.com/page/ to redirect to http://domain.com/page/?Campaign_ID=123456

The way i tried to set it up is giving me a redirect loop error message when i try to visit domain.com/page:

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

I also tried it with RewriteRule instead, and that is also giving me the loop message:

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

i'm sorry if this question has already been answered on here. i searched for awhile and couldn't find it, so please don't yell at me for posting. i did try to find it on my own. thanks!

2条回答
Summer. ? 凉城
2楼-- · 2019-08-03 09:22

Give this a try:

RewriteCond %{REQUEST_URI} ^(/page/)(.*)$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1?Campaign_ID=1234656 [L,R=301]
查看更多
姐就是有狂的资本
3楼-- · 2019-08-03 09:44

Try:

RewriteEngine On
RewriteBase /

RewriteRule ^index\.php$ - [L]

RewriteCond %{QUERY_STRING} ^$
RewriteRule ^page/?$ http://domain.com/page/?Campaign_ID=1234656 [L,NE,R=301]
查看更多
登录 后发表回答