I have setup some rules in which subdomains (my users) will default to where I have located the robots.txt, favicon.ico, and crossdomain.xml
therefore if a user creates a site say
testing.mywebsite.com and they don't make their own favicon.ico at testing.mywebsite.com/favicon.ico, then it will use the favicon.ico I have in /misc/favicon.ico
This works perfect, but it doesn't work for the main website. If you attempt to go to
mywebsite.com/favicon.ico it will check if "/" exists, in which it does. And then never redirects to /misc/favicon.ico
How can I get it so both instances redirect to /misc/favicon.ico ?
# Set all crossdomain (openxxx file) favorite icons and robots.txt doesnt exist on their
# side, then redirect to site's just to have something to go on.
RewriteCond %{REQUEST_URI} crossdomain.xml$
RewriteCond ^(.+)crossdomain.xml !-f
RewriteRule ^(.*)$ /misc/crossdomain.xml [L]
RewriteCond %{REQUEST_URI} favicon.ico$
RewriteCond ^(.+)favicon.ico !-f
RewriteRule ^(.*)$ /misc/favicon.ico [L]
RewriteCond %{REQUEST_URI} robots.txt$
RewriteCond ^(.+)robots.txt !-f
RewriteRule ^(.*)$ /misc/robots.txt [L]
Edit:
Here is my full Vhost if it helps in diagnosing:
<VirtualHost *>
ServerName www.mysite.com
ServerAdmin webmaster@mysite.com
DocumentRoot /var/www/mysite/
<Directory /var/www/mysite/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/apache2/mysite_error.log
LogLevel warn
CustomLog /var/log/apache2/mysite_access.log combined
ServerSignature on
RewriteEngine on
#RewriteLog "/var/log/apache2/rewrite.log"
#RewriteLogLevel 9
RewriteCond %{HTTP_HOST} ^www.mysite.com$ [NC]
RewriteRule ^(.*)$ - [L]
RewriteCond %{HTTP_HOST} ^mysite.com$ [NC]
RewriteRule ^(.*)$ http://www.mysite.com$1 [NC,L,R=302]
# If there is a subdomain and the subdomain has a /home/ directory attached to it then
# rewrite the HTTP_HOST into the URI so we can process it. If its /media/, go to their
# media folder, otherwise to their www folder.
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+?)\.mysite\.com$
RewriteCond /home/%1/ -d
RewriteRule ^(.+) %{HTTP_HOST}$1
RewriteRule ^(?:www\.)?([^.]+?)\.mysite\.com/media/(.*) /home/$1/xxx/media/$2 [L]
RewriteRule ^(?:www\.)?([^.]+?)\.mysite\.com/(.*) /home/$1/www/$2
# Set all crossdomain (openpalace file) favorite icons and robots.txt doesnt exist on their
# side, then redirect to mainsite's just to have something to go on.
RewriteCond %{REQUEST_URI} crossdomain.xml$
RewriteCond ^(.+)crossdomain.xml !-f
RewriteRule ^(.*)$ /misc/crossdomain.xml [L]
RewriteCond %{REQUEST_URI} favicon.ico$
RewriteCond ^(.+)favicon.ico !-f
RewriteRule ^(.*)$ /misc/favicon.ico [L]
RewriteCond %{REQUEST_URI} robots.txt$
RewriteCond ^(.+)robots.txt !-f
RewriteRule ^(.*)$ /misc/robots.txt [L]
# Same as above but this is for if the directory doe's not exist. Typically it would be
# wise to put this into a skip to emulate an if/else but it would also match if the
# HTTP_HOST was anything. The skip If/Else method only works with 1 IF, 2
# Don't put this as the last thing, there could be redirects later on that may not have a
# /home/ dir but are just shortcuts to things, like inbox.mysite.com
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+?)\.mysite\.com$
RewriteCond /home/%1/ !-d
RewriteRule ^(.*)$ http://www.mysite.com$1 [R=302]
#Extract the subdomain (if there is one), domain, and tld. Check id the domain exists in
#/home/. If it does then rewrite URL to http_host and then see if it can apply to media.
# There has to be two pairs of rewriteCond because it only applies to the next rule.
#www. domain . tld
RewriteCond %{HTTP_HOST} ^(?:.*\.)?([^.]+)\.(?:[^.]+)$
RewriteCond /home/%1/ -d
RewriteRule ^(.+) %{HTTP_HOST}$1 [C]
RewriteRule ^(?:.*\.)?([^.]+)\.(?:[^.]+?)/media/(.*)$ /home/$1/xxx/media/$2 [L]
#www. domain . tld
RewriteCond %{HTTP_HOST} ^(?:.*\.)?([^.]+)\.(?:[^.]+)$
RewriteCond /home/%1/ -d
RewriteRule ^(?:.*\.)?([^.]+)\.(?:[^.]+?)/(.*)$ /home/$1/www/$2 [L]
</VirtualHost>