I have domain.com
and sub.domain.com
pointing to the same server and I'm using mod_rewrite to rewrite URLs for sub.domain.com
to the sub
subdirectory. I have the following .htaccess
file in the document root:
DirectoryIndex index.html index.php
# Prevent infinite rewrite loop.
RewriteCond %{ENV:REDIRECT_STATUS} ^$
# Send all requests addressing sub.domain.com...
RewriteCond %{HTTP_HOST} =sub.domain.com [NC]
# ...to the /sub directory.
RewriteRule ^ /sub%{REQUEST_URI} [QSA]
Within the sub
directory I have index.php
and no index.html
, but requests to http://sub.domain.com
seem to ignore index.php
altogether and return 404. If I have index.html
there, however, its is served. The only way I could get index.php
to be served is to set
DirectoryIndex index.php
but that is not something I want to do for the entire site.
Oddly enough, URLs other than the document root exhibit normal DirectoryIndex
behavior. For example, http://sub.domain.com/search
tries looks for sub/search/index.html
then sub/search/index.php
before returning 404.
If I query the sub
directory from the parent domain http://domain.com/sub
, I'm able to see index.php
, which leaves me completely dumbfounded with the issue.
I'd include the Apache error log, but I'm using shared hosting and have no way to increase logging verbosity. Also, I was unable to reproduce this error locally. The web hosting server is using Apache 2.4.3, and my local server is Apache 2.4.9.
DirectoryCheckHandler On
to your apache config? docsDirectoryCheckHandler
, they state that "Releases prior to 2.4 implicitly act as if 'DirectoryCheckHandler ON' was specified." My local Apache server should have this directive OFF by default, and I guess the hosting server should have it OFF (since it's a 2.4 release). IfDirectoryCheckHandler
behavior is the rootcause, wouldn't I see it on both servers?DirectoryCheckHandler
on the hosted server since it's not available in that version.