I am running WordPress 3.1 with multisite enabled. I have multiple websites all sharing the same .htaccess file in the web root directory. I am using RewriteCond to target specific websites and apply RewriteRules to each site. Unfortunately it is not working as expected. Here is what I have in my .htaccess file:
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# Blog1 Rewrite Rules which should only apply to blog1.mydomain.com
RewriteCond %{HTTP_HOST} ^blog1\.mydomain\.com [nc]
RewriteRule ^fileabc\.jpg$ http://blog1.mydomain.com/files/2011/05/fileabc.jpg [R=301,NC,L]
RewriteRule ^filexyz\.pdf$ http://blog1.mydomain.com/wp-content/themes/blog1Theme/Files/filexyz.pdf [R=301,NC,L]
# Blog2 Rewrite Riles which should only apply to blog2.com
RewriteCond %{HTTP_HOST} ^Blog2\.com [nc]
RewriteRule ^index\.html$ http://Blog2.com/index.php [R=301,NC,L]
RewriteRule ^page\.html$ http://Blog2.com/page/ [R=301,NC,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule . index.php [L]
I use RewriteCond to target a specific site (blog1.mydomain.com or blog2.com) and they have specific RewriteRules for each.
However, The ReWriteRules are being applied to both websites (blog1.mydomain.com and blog2.com).
For example:
Accessing blog1.mydomain.com/fileabc.jpg should redirect to http://blog1.mydomain.com/files/2011/05/fileabc.jpg
However, accessing Blog2.com/fileabc.jpg also redirects to http://blog1.mydomain.com/files/2011/05/fileabc.jpg
So the RewriteRules are being applied to both (all) site, not just the ones specified by the RewriteCond.
Help is much appreciated!
From Apache page
Now your rules
RewriteCond is valid only for first rewriteRule immediately following it , not for all rules below it.So second rewriteRule will match any domain.