Query string redirection with htaccess?

RewriteRule does not work with query string directly -- you have to use RewriteCond for that Here is the rule -- it will redirect (301 Permanent Redirect) ANY URL that has more than 1 parameter in query string and 1 of them is ref RewriteEngine On RewriteCond %{QUERY_STRING} (^|&)ref=(^&*)(&|$) RewriteCond %{QUERY_STRING}! ^ref=(^&*)$ RewriteRule . * http://%{HTTP_HOST}%{REQUEST_URI}?

Ref=%2 R=301,L For example: It will redirect http://www.example.com/hello.php?id=86&name=John&ref=12d34888&me=yes to the same URL but with ref parameter only: http://www.example.com/hello.php?ref=12d34888 It will do nothing if only ref parameter is present or no parameter at all, e. G http://www.example.com/hello.php?ref=12d34888 or http://www.example.com/hello.php If such redirect should only work for website root hits, then change the RewriteRule line to this: RewriteRule ^$ http://%{HTTP_HOST}/? Ref=%2 R=301,L (this is if placed in .

Htaccess file in website root folder -- if placed in server config / virtual host context the rule needs to be slightly tweaked) http://www.example.com/?id=86&name=John&ref=12d34888&me=yes http://www.example.com/?ref=12d34888 If it has to be redirected to another domain, then replace %{HTTP_HOST} by domain specific name, e. G: RewriteRule ^$ http://www.exampe.com/?ref=%2 R=301,L It all has been tested before posting.

RewriteRule does not work with query string directly -- you have to use RewriteCond for that. Here is the rule -- it will redirect (301 Permanent Redirect) ANY URL that has more than 1 parameter in query string and 1 of them is ref RewriteEngine On RewriteCond %{QUERY_STRING} (^|&)ref=(^&*)(&|$) RewriteCond %{QUERY_STRING}! ^ref=(^&*)$ RewriteRule .

* http://%{HTTP_HOST}%{REQUEST_URI}? Ref=%2 R=301,L For example: It will redirect http://www.example.com/hello.php?id=86&name=John&ref=12d34888&me=yes to the same URL but with ref parameter only: http://www.example.com/hello.php?ref=12d34888. It will do nothing if only ref parameter is present or no parameter at all, e.g. http://www.example.com/hello.php?ref=12d34888 or http://www.example.com/hello.php.If such redirect should only work for website root hits, then change the RewriteRule line to this: RewriteRule ^$ http://%{HTTP_HOST}/?

Ref=%2 R=301,L (this is if placed in . Htaccess file in website root folder -- if placed in server config / virtual host context the rule needs to be slightly tweaked). http://www.example.com/?id=86&name=John&ref=12d34888&me=yes -> http://www.example.com/?ref=12d34888 If it has to be redirected to another domain, then replace %{HTTP_HOST} by domain specific name, e.

G: RewriteRule ^$ http://www.exampe.com/?ref=%2 R=301,L It all has been tested before posting.

Wow! Thank you so much for the detailed explanation. I'll comment again once I've tested it.

– Tom Hartman Aug 9 at 18:18 It works just as I needed it to. Thank you LazyOne Kenobi. You were my only hope.

– Tom Hartman Aug 9 at 18:34 @Tom Glad to hear. You can mark the answer as accepted then :) – LazyOne Aug 9 at 18:37 Done and done! Really, thanks again.

– Tom Hartman Aug 9 at 19:13.

Ref=$1 L is about as simple as it guess, but this will screw up if the ref query var isn't the last thing in the line - it'll slurp up everything after ref= and redirect that to, so /blah&ref=abc&blahblahblah would turn into /ref=abc&blahblahblah.

Thank you much Marc! I may indeed use this despite the caveat. Would you perhaps be able to point me in the right direction should I want to obtain the exact value instead of everything after the ref parameter?

– Tom Hartman Aug 9 at 17:24 possibly ref=(.*? )^&+ – Marc B Aug 9 at 17:27 Much obliged, I'll give that a shot. – Tom Hartman Aug 9 at 17:39 RewriteRule does not work with query string parameters directly – LazyOne Aug 9 at 17:42 Thanks LazyOne, what would you suggest I use instead?

– Tom Hartman Aug 9 at 17:55.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions