I already have two rewrite rules that work correctly, but another code needs to be added to work perfectly.
I have a website hosted on mydomain.com and all subdom.mydomain.com are rewritten to mydomain.com/subs/subdom. My CMS should handle the request, if the existing file does not exist, the rewriting is done as follows:
RewriteCond $1 !^subs/ RewriteCond %{HTTP_HOST} ^([^.]+)\.mydomain\.com$ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ subs/%1/index.php?page=$1 [L]
My CMS handles the next part of the parsing as usual. The problem is that the file really exists, I need to link it without going through my CMS, I managed to do it as follows:
RewriteCond $1 !^subs/ RewriteCond %{HTTP_HOST} ^([^.]+)\.mydomain\.com$ RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^(.*)$ subs/%1/$1 [L]
So far it looks like a charm. Now I am picky, and I need to have the default files, which are stored in subs / default /. If the file exists in the subdomain folder, we must capture it, but if not, we need to get the file from the default subdomain. And if the file does not exist anywhere, we should use page 404 from the current subdomain, if not.
I hope this will be described fairly well. Thank you for your time!
source share