Use htaccess to append a query string to URL

百般思念 提交于 2019-12-11 12:15:22

问题


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!


回答1:


Try:

RewriteEngine On
RewriteBase /

RewriteRule ^index\.php$ - [L]

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



回答2:


Give this a try:

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


来源:https://stackoverflow.com/questions/24151901/use-htaccess-to-append-a-query-string-to-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!