Mobile app version of vmapp.org
Login or Join
Holmes151

: .htaccess Redirect based on subdomain I'm looking for some help in accomplishing redirects based on the subdomain. For example if some tries to access: http://1.test.com it will redirect to:

@Holmes151

Posted in: #Htaccess #MultiSubdomains #Redirects #Subdomain

I'm looking for some help in accomplishing redirects based on the subdomain. For example if some tries to access:


1.test.com

it will redirect to:


/file.php?test=something


and if they go to:


2.test.com

it will redirect to:


/file.php?test=somethingelse


I only need the root redirected, so if they go to:


1.test.com/blah

it will not redirect.

I know the basics of creating htaccess files, I just can't seem to get it right for some reason to accomplish this. Any help is highly appreciated.

Thanks.

P.S. I should mention that all these subdomains point to the same document root.

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Holmes151

1 Comments

Sorted by latest first Latest Oldest Best

 

@Gretchen104

With mod_rewrite active try

RewriteEngine on
RewriteCond %{HTTP_HOST} !^1.test.com$
RewriteRule ^$ /file.php?test=something [L,R=301]
RewriteCond %{HTTP_HOST} !^2.test.com$
RewriteRule ^$ /file.php?test=somethingelse [L,R=301]

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme