Forum Moderators: phranque
I am using a wildcard alias for the subdomains, and the according changes have been made to the server config and dns. So all files are in the same directory. This is working fine.
So far I have the htaccess working, mostly. www.example.com and example.com go to the index1.php and works perfectly. subdomain.example.com goes to index2.php like it is supposed to as well.
The problem that I am having is that any time I try to go to subdomain.example.com/anything_other_than_index2.php, I get a 404 error.
I am missing something in my htaccess file to make it all work, but I have no idea what that is. As you can see, Index1.php is my default index, since I do not have a index.html or index.htm.
DirectoryIndex index.html index.htm index1.php index.phpOptions -Indexes
Options +FollowSymlinks
<IfModule mod_rewrite.c>
RewriteEngine On
#Code for changing default index for subdomains
#No change for www.example.com - go to normal index1.php
RewriteCond %{HTTP_HOST}!^www\.example\.com [NC]
#Take effect for subdomain.example.com
RewriteCond %{HTTP_HOST} ^(.*)\.example\.com
#Where I am having issues...
RewriteCond %{REQUEST_URI}!^/index2.php [NC]
#Pull up index2.php for subdomain instead of default index1.php
RewriteRule (.*) /index2.php$1 [L]
So I think the issues are with the line: RewriteCond %{REQUEST_URI}!^/index2.php [NC]
If I change it to!^/(.*), I no longer get 404 errors, but my subdomains no longer go to index2.php either.
The logic needs to work like this: If you are using a subdomain and trying to go to default index1.php, go to index2.php as default instead. If you are using a subdomain and trying to go to any file except index1.php or index2.php, allow all other files to come through with no change.
But as the code is, when using a subdomain and trying to access anything other than index2.php (IE subdomain.example.com/blah.php), I get a 404 error. Keep in mind all of my files are in the same directory, as I am using a wildcard in the config and dns.
Please help. I have put hours and hours into this and have got this far on reading tons and trial and error. Thank you and Happy Easter!