Forum Moderators: phranque

Message Too Old, No Replies

Do .htaccess files in web root apply to subdomains?

         

zollerwagner

5:39 am on Jun 10, 2007 (gmt 0)

10+ Year Member



If I have an .htaccess file in the root of the site, does it apply to a subdomain on the same site and server?

The subdomain appears in the file manager as a subdirectory, but was created as a subdomain in CPanel.

jdMorgan

2:54 pm on Jun 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That depends on exactly how the subdomain is mapped to the subdirectory by cPanel. If it's done using an internal rewrite, then the .htaccess would apply. If it's done using a separate VirtualHost container (containing a separate DocumentRoot directive) or by using an Alias directive, then .htaccess in the main domain's root would not apply.

The simplest way to find out is to put a harmless redirect in the main site's .htaccess, and then test it from the subdomain -- something like redirecting a non-linked, non-existent page URL to google.com or similar.

For example, in example.com/.htaccess


RedirectMatch 302 /test-page\.html$ http://www.google.com/

Then request subdomain.example.com/test-page.html. If you end up at google, then the main domain's .htaccess was applied to the subdomain page request.

Note that the RedirectMatch pattern is not start-anchored. That is to make it insensitive to the subdirectory's path, mainly because I'm not sure exactly what it would be or how it might vary depending on cPanel's implementation of the subdomain-to-subdirectory mapping.

Also, be aware that using cPanel and other "control panels" can destroy any custom .htaccess file you may have, because these control panels use templates to generate code, and can overwrite all or parts of your file. So if you have a custom .htaccess file, either always make a fresh backup of your .htaccess file and then copy/merge the new cPanel-created code into it manually, or don't use the cPanel functions that modify .htaccess.

Jim

zollerwagner

7:06 am on Jun 11, 2007 (gmt 0)

10+ Year Member



Thanks, JDMorgan! Your suggestion was a good way to test.

With just one .htaccess in the root, using that url with either the root or subdomain, caused a redirect to Google.

System

4:16 pm on Jun 11, 2007 (gmt 0)

redhat



The following 2 messages were cut out to new thread by jdmorgan. New thread at: apache/3364944.htm [webmasterworld.com]
9:16 pm on June 11, 2007 (CDT -5)