为WordPress多站点添加RewriteRule

时间:2013-05-02 18:10:26

标签: wordpress .htaccess mod-rewrite

我在子目录上有一个全新的WP多站点网络(v 3.5.1)。我收到图片的错误,其中子网站无法正确显示它们,但它们正在正确上传。我很确定我需要做的就是将正确的RewriteRule添加到主站点的.htaccess文件中,如下所示:

从网站的任何位置调用图片时,网址为:example.com/subsitename/assets/sites/#/imagename.jpg。我想更改它,以便图像实际来自:example.com/assets/sites/#/imagename.jpg,其中subsitename#imagename.jpg都是变量。

看起来这应该非常简单,但我很难找到正确的语法或解决此问题的其他人的例子。有谁知道我会添加适当的RewriteRule?

我当前的.htaccess文件包含:

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]

1 个答案:

答案 0 :(得分:2)

请改为尝试:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]        

# uploaded files
RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [L]

# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule  ^[_0-9a-zA-Z-]+/(wp-(content|admin|includes).*) $1 [L]
RewriteRule  ^[_0-9a-zA-Z-]+/(.*\.php)$ $1 [L]
RewriteRule . index.php [L]
</IfModule>
# END WordPress