开发者

Wordpress Multisite Rewrite Rules

开发者 https://www.devze.com 2023-03-09 08:59 出处:网络
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

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

The order of rules in the ruleset is important because the rewrite engine processes them in a particular (not always obvious) order, as follows: The rewrite engine loops through the rulesets (each ruleset being made up of RewriteRule directives, with or without RewriteConds), rule by rule. When a particular rule is matched, mod_rewrite also checks the corresponding conditions (RewriteCond directives). For historical reasons the conditions are given first, making the control flow a little bit long-winded.

first the URL is matched against the Pattern of a rule. If it does not match, mod_rewrite immediately stops processing that rule, and goes on to the next rule. If the Pattern matches, mod_rewrite checks for rule conditions. If none are present, the URL will be replaced with a new string, constructed from the Substitution string, and mod_rewrite goes on to the next rule.

Now your rules

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]

RewriteCond is valid only for first rewriteRule immediately following it , not for all rules below it.So second rewriteRule will match any domain.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号