WordPress 多站点重写规则

发布于 2024-11-10 11:25:13 字数 1530 浏览 0 评论 0原文

我正在运行启用多站点的 Wordpress 3.1。我有多个网站在网站根目录中共享相同的 .htaccess 文件。我使用 RewriteCond 来定位特定网站并将 RewriteRules 应用于每个网站。不幸的是它没有按预期工作。以下是我的 .htaccess 文件中的内容:

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]

我使用 RewriteCond 来定位特定站点(blog1.mydomain.com 或 blog2.com),并且每个站点都有特定的 RewriteRules。

但是,ReWriteRules 正在应用于两个网站(blog1.mydomain.com 和 blog2.com)。

例如:

访问 blog1.mydomain.com/fileabc.jpg 应重定向到 http:// /blog1.mydomain.com/files/2011/05/fileabc.jpg

但是,访问 Blog2.com/fileabc.jpg 也会重定向到 http://blog1.mydomain.com/files/2011/05/fileabc.jpg

因此,RewriteRules 将应用于两个(所有)站点,而不仅仅是 RewriteCond 指定的站点。

非常感谢帮助!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沙沙粒小 2024-11-17 11:25:13

来自 Apache 页面

规则集中规则的顺序是
重要的是因为重写引擎
以特定方式处理它们(不是
总是显而易见的)顺序,如下:
重写引擎循环通过
规则集(每个规则集由
RewriteRule 指令的数量,带有 或
没有 RewriteConds),逐条规则。
当匹配特定规则时,
mod_rewrite 还检查
相应的条件(RewriteCond
指令)。由于历史原因
首先给出条件,使得
控制流程一点点
啰嗦了。

首先将 URL 与
规则的模式。如果没有
匹配,mod_rewrite立即停止
处理该规则,然后继续
下一条规则。如果模式匹配,
mod_rewrite 检查规则
状况。如果不存在,则
URL 将被替换为新的
字符串,由
替换字符串和 mod_rewrite
继续下一条规则。

现在,您的规则

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 仅对紧随其后的第一个 rewriteRule 有效,而不对其下面的所有规则有效。因此第二个 rewriteRule 将匹配任何域。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文