Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
196 views
in Technique[技术] by (71.8m points)

apache - Modify query string value using htacces

I want to redirect

https://www.example.com/signup?plan=basic to https://www.example.com/signup?plan=basic-monthly and https://www.example.com/signup?plan=pro to https://www.example.com/signup?plan=pro-monthly .

How can I achieve this using htaccess ?

There are many questions related to this here. But, couldn't find an answer for this specific scenario.

This is the code I tried and failed:

RewriteCond %{QUERY_STRING} (^|&)plan=pro(&|$)
RewriteRule ^signup /$0?plan=pro-monthly [R=301,L]

Also, while trying the same with "basic" instead of "pro", the word "basic" i shown in red color as if it is a keyword.

question from:https://stackoverflow.com/questions/65914257/modify-query-string-value-using-htacces

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Could you please try following, written with shown samples. Please make sure you clear your browser cache before testing your URLs.

RewriteEngine ON
RewriteCond %{QUERY_STRING} ^(plan=(?:basic|pro))$ [NC]
RewriteRule ^(signup)/?$ $1?%1-monthly [L]


2nd solution: Or you could try following too. Make sure you either put 1st solution rules OR this one at a time.

RewriteEngine ON
RewriteCond %{THE_REQUEST} s/(signup)?(plan=(?:basic|pro))s [NC]
RewriteRule ^ %1?%2-monthly [L]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...