Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

fake virtual subdomain

10:23 am on Oct 17, 2013 (gmt 0)

New User

10+ Year Member

joined:Jan 2, 2007
posts: 33
votes: 0


On my website I uses virtual subdomains.
In my .htaccess I have the following rules:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.site\.com?$
RewriteCond %{HTTP_HOST} ^([^.]+)\.site\.com?$
RewriteRule ^$ /subdomain.php?subdomain=%1 [L]

It should works like this:
http: // subdomain.site.com display the content of subdomain.php

This is OK!

http:// WWW .subdomain.site.com/ display the content of the http:// www .site.com WHICH is wrong. I want all www. subdomain.site.com be redirected to www. site.com

If I type http :// subdomain.site.com/category/name_of_category I am redirected to http: // WWW .subdomain.site.com/category/name_of_category and it is diaplyed the content of http: // www. site.com/category/name_of_category
Instead of that I need a 404 error response.
How can I resolve this problem ?

Thank you very much!
10:41 pm on Oct 17, 2013 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
votes: 491



Host can be exactly www.example.com OR exactly www.example.co. Maybe, but I strongly suspect you mean



<further tangent>
Find and read the boilerplate on using "example.com". There are many reasons for it. But auto-linking only kicks in when there's a preceding http://
</further tangent>

http://WWW.subdomain.example.com/ display the content of the http://www.example.com WHICH is wrong. I want all www.subdomain.example.com be redirected to www.site.com

Where is the code that says so?

If I type http://subdomain.example.com/category/name_of_category I am redirected to http://WWW.subdomain.example.com/category/name_of_category

Then there must be additional RewriteRules involved, because-- independent of any hostname issues-- the quoted rule only applies to requests for the root ^$ From the information given, it's impossible to tell whether we're dealing with the results of other rules in the same htaccess, or rules at the host/config level.

By the way, I hope that wasn't a verbatim quote from htaccess, since it would imply that the subdomain rewrite is the very first RewriteRule. It should be one of the last, after any explicit redirects are out of the way.