WordPress 多站点重写规则
我正在运行启用多站点的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
来自 Apache 页面
现在,您的规则
RewriteCond 仅对紧随其后的第一个 rewriteRule 有效,而不对其下面的所有规则有效。因此第二个 rewriteRule 将匹配任何域。
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.