views:

15

answers:

1

Hi,

I've searched and tried many examples but none seem to work for me. I need to redirect a request to a specific url depending on if the original request had a certain item in it's query string.

e.g.

www.mydomain.com/test.html?username=foo&password=bar

So I want to redirect this only is the username variable is present in the query string to

www.mydomain.com/home.html?username=foo&password=bar

But also, the page could be any page, .e.g test.html, home.html, contact.php

So if username variable is detected in query string, then the redirect will happen only.

thanks for your help.

I tried this but it did not work:

RewriteRule ^username(.*)$ test.html?username=$1 [L,QSA]

A: 

You can use QUERY_STRING to accomplish this.

RewriteCond %{QUERY_STRING} username
RewriteCond %{REQUEST_URI} !^/home.html
RewriteRule .* /home.html/ [L,QSA]
jasonbar
thanks. I've tried this but it does not seem to work. Also, what does the 2nd line do?"RewriteCond %{REQUEST_URI} !^/home.html"
k22k
when I remove the 2nd line: "RewriteCond %{REQUEST_URI} !^/home.html", it seems to work but I get a 500 Internal Server Error
k22k
@k22k, The second line keeps the rewrite rule from applying to your final destination (and falling into a redirect loop). If home.html is NOT the final script that handles this, you need to change it appropriately.This works for me, is it just not redirecting for you?
jasonbar
got it working. I just need to add "Options +FollowSymlinks" to the htaccess file
k22k