I'm trying to configure mod_rewrite to attempt to load/serve files in a specific order. I think the easiest way to describe what I'm trying to achieve is with an example.
Let's say in my document root the following files/folders exist:
/missing.html
/subdomain.example.com/index.html
/subdomain.example.com/other_page.html
/folder1/index.html
/folder1/other_page.html
In order, the file return should be: 1) The folder/path requested 2) The folder/path requested, prepended with the hostname 3) The 'missing.html' file
For example:
http://example.com/folder1/ -> /folder1/index.html
http://example.com/folder1/other_page.html -> /folder1/other_page.html
http://example.com/folder1/nonexistant_file.html -> /missing.html
http://subdomain.example.com/ -> /subdomain.example.com/index.html
http://subdomain.example.com/other_page.html -> /subdomain.example.com/other_page.html
http://subdomain.example.com/nonexistant_file.html -> /missing.html
http://some_other_subdomain.example.com/ -> /missing.html
So far I've managed to get this mostly working, but I'm having trouble with the 'missing.html' part. Anything that I would expect to be processed results in a 500 error.
I can't figure out if what I'm trying to achieve can be done with mod_rewrite alone.. the documentation doesn't make a huge amount of sense to me!
Here's my .htaccess so far:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule (.*) $1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) %{HTTP_HOST}/$1 [L,QSA]
RewriteRule (.*) missing\.html [L]
Any input would be greatly appreciated!
Michael