2

I have a dynamic query string that I need to pass via an .htaccess redirect. For example:

I need to redirect this URL: http://mysite.com/page1?action=signup&var2=dynamicVar

To this: http://mysite.com?action=signup&var2=dynamicVar

I know this is pretty simple, but I'm really not sure what type of rule/syntax would work for this.

Any help is greatly appreciated!

4 Answers 4

2

If you already have .htaccess then simply add this line:

RewriteRule ^page1/?$ page2 [L,R,QSA,NC]

Update: Based on your comments:

RewriteCond %{QUERY_STRING} (^|&)action=signup(&|$) [NC]
RewriteRule ^page1/?$ / [L,R,QSA,NC]
Sign up to request clarification or add additional context in comments.

7 Comments

This looks like exactly what I'm trying to do. However, I mis-spoke in my question. I really need to redirect this: mysite.com/page1?var=dynamicVar To this: mysite.com?var=dynamicVar . Any idea on how could do that?
Thanks for your quick response, however, I wasn't totally clear again (sorry!). I've revised my original post above. The big thing is that I only need to redirect if the first part of the query string matches 'action=signup'.
Ah the ever changing requirements :) Anyway I edited again, check it now.
Thanks again! Unfortunately, this doesn't appear to be doing anything. I made sure to change 'page1' to 'login' per my example URLs. Any idea clue why it wouldn't be working? I appreciate your generous help!
On second thought, the only thing I think that would cause this to not work is the fact that my urls have a '/' between the directory and the start of the query string. Could this be the cause?
|
0
RewriteRule ^page1(.*)$ /page2$1 [L,R=301]

Comments

0

Input

http://mysite.com/page1?action=signup&var2=dynamicVar

this is the rewrite rule

RewriteRule ^page1?(.*)$ /?$1 [L,R=301]

redirect to

http://mysite.com/?action=signup&var2=dynamicVar 

this will redirect all request o page1 with get parameters to http://mysite.com

Comments

-1

Use %{REQUEST_URI} fi.:

RewriteCond %{HTTP_HOST} ^website\.(.+)$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

rewrites anything that starts with "website" to "www.website..." including the querystring (by use of %{REQUEST_URI})

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.