htaccess query_string redirect only when string equals a specific value

admin

Administrator
Staff member
I've been searching for hours on how to do this and feel as if I'm close.

I am trying to redirect specific visitors to a different page on my site based on the string parameters passed in the URL.

For exmaple, I want the URL mysite.com/index.php?src=msn&test=1 to be redirected to mysite.com/msn/index.php?src=msn&test=1

I am planning on my normal site visitors to access the index.php page without being re-directed, so it should only redirect when the query string matches the value I set.

Here is my code:

Code:
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{QUERY_STRING} ^src=msn(.*)$
RewriteRule ^(.*)$ http://www.mysite.com/msn/ [L]

The above code works when I go to the URL mysite.com/?src=msn&test=1 but it does not work for mysite.com/index.php?src=msn&test=1. Any idea how I can get it to work when I enter index.php?

Thanks.

EDIT:::

I also have the following rules in my .htaccess file:

Code:
 ErrorDocument 404 /error404.php

 <IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteBase /blog/
 RewriteRule ^index\.php$ - [L]
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule . /blog/index.php [L]
 </IfModule>

 RewriteEngine on
 RewriteCond %{HTTP_HOST} ^mywebsite\.com$ [NC]
 RewriteRule ^(.*)$ http://www.mywebsite.com/$1 [R=301,L]

The first is a 404 redirect, second is a wordpress file change, and the last forces all pages to be <a href="http://www">http://www</a>.