Arun Chandran
Arun Chandran

Reputation: 330

htaccess redirect with query string

I've url with a link parameter in it. I want redirect this to a php file. How can I implement this using htaccess file?

Source url: www.example.com/?id=15&L=1&link=androidapp

Target url: www.example.com/test.php

I want to check if "link=androidapp" exists, then redirect to the php file.

I've tried the following code, but not working;

RewriteCond %{QUERY_STRING} ^link=androidapp$ 
RewriteRule ^(.*)$ http://www.example.com/test.php? [R=301,L]

Can you guys please help me to solve the problem? Thanks.

Upvotes: 0

Views: 1531

Answers (2)

Croises
Croises

Reputation: 18671

Use this:

RewriteCond %{QUERY_STRING} link=androidapp(&|$) 
RewriteRule ^ http://www.example.com/test.php? [R=301,L]

Upvotes: 0

Mario A
Mario A

Reputation: 3363

It should work if you skip the ^ and the $ like this:

RewriteCond %{QUERY_STRING} link=androidapp 
RewriteRule ^(.*)$ http://www.example.com/test.php? [R=301,L]

The ^ means that the your pattern matches only from the beginning of the querystring, but your querystring begins with id=15...

Upvotes: 1

Related Questions