1

I need to set up a redirection to sub domain based on query string.

Example: http://example.com/message.php?id=subdomain to http://subdomain.example.com/message.php

Is this possible in .htaccess?

1 Answers1

0

This will redirect all the URLs with QUERY_STRING like id=subdomain and file message.php to the appropriate subdomain:

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

Mind the question mark at the end of message.php? - it is used to suppress appending the old QUERY_STRING. I added the domain name check to avoid the possibility of eternal redirect loop.

user4035
  • 22,508
  • 11
  • 59
  • 94