homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

.htaccess detect subdomain

Msg#: 4402782 posted 1:54 pm on Jan 1, 2012 (gmt 0)

I have a few folders that need to act differently depending on whether they are accessed from the root domain or a subdomain. I basically need .htaccess to do something like:

do something
else if(domain.com)
do something else

Is this possible with .htacces?

Thanks in advance



WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member

Msg#: 4402782 posted 2:27 pm on Jan 1, 2012 (gmt 0)

RewriteCond %{HTTP_HOST} ^....
RewriteRule .... .... [L]


WebmasterWorld Senior Member lucy24 us a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month

Msg#: 4402782 posted 8:41 pm on Jan 1, 2012 (gmt 0)

Better come back and explain in English what you mean by "accessed from", because my answer would have involved %{HTTP_REFERER}.

:: memo to self: figure out how to expand MSIE 6 exception to allow people to visit more than one page without opening the door to auto-referring robots ::


Msg#: 4402782 posted 10:57 pm on Jan 1, 2012 (gmt 0)

In a nutshell, I work on local folders for pre-release site testing. My live site (domain.com) is always pointed to a folder named AALIVE, while my #1 test site (test.domain.com) points to AATEST1. When testing is complete I have a script that renames AALIVE->OLDx, and AATEST1->AALIVE, effectively setting the test site as live while maintaining the old site in case I have to revert.

I just realized that google has indexed my test domains, which I am trying to stop. My thought was to identify whether the folder was being accessed from domain.com or test.domain.com, and allow only my ip for the test site.

I am open to suggestions to help sort this out... any thoughts will be greatly appreciated!


Msg#: 4402782 posted 1:55 pm on Jan 2, 2012 (gmt 0)

After much research I think I need to use something like the following:

SetEnvIf HOST ^*test.*$ HOST_TEST

<IfDefine HOST_TEST>

This should set the environment variable HOST_TEST if the subdomain consists of test, then require authentication. However, I'm sure I have something wrong as I'm getting an internal server error, and would appreciate a second set of eyes.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved