Media804
Media804

Reputation: 41

Passing a Query String via .HTACCESS

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!

Upvotes: 2

Views: 837

Answers (4)

TlmaK0
TlmaK0

Reputation: 3896

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

Upvotes: 0

anubhava
anubhava

Reputation: 785156

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]

Upvotes: 2

Eddy Freddy
Eddy Freddy

Reputation: 1816

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

Upvotes: 0

Coert van Gemeren
Coert van Gemeren

Reputation: 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})

Upvotes: -1

Related Questions