使用 nginx 重写 Wordpress 3 Multiuser 中子目录的规则?

发布于 2024-09-14 14:12:15 字数 608 浏览 9 评论 0原文

我的 Wordpress 3 多用户已启用,但我不知道如何为 nginx 重写以下 .htaccess 规则:

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).*) $2 [L]
RewriteRule  ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]

有任何提示吗?

My Wordpress 3 multiuser has been enabled, but I don't know how to rewrite the following .htaccess rules for nginx:

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).*) $2 [L]
RewriteRule  ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]

Any hints?

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

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

发布评论

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

评论(1

柠檬 2024-09-21 14:12:15

这些代码不起作用:(我已经对它们做了一些更改,但在wordpress3.0.1中仍然不起作用)

    rewrite ^index\.php$ - last;

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

    # add a trailing slash to /wp-admin
    rewrite ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ permanent;

    if ( -e $request_filename ) {
            rewrite ^ - last;
            rewrite ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 last;
            rewrite ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 last;
            rewrite . index.php last;
    }

我已经尝试过了,

我用apache2在virtualbox中构建了wordpress3.0.1,只是找到了.htaccess文件如下所示:

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

RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]

所以 nginx 重写规则应该是:

location ~ / {
    rewrite ^index\.php$ - last;
    if( !-e $request_filename ) {
        rewrite . /index.php last;
    }
}

这有效!

These codes do not work:(I have done some changes with them, but still not work in wordpress3.0.1)

    rewrite ^index\.php$ - last;

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

    # add a trailing slash to /wp-admin
    rewrite ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ permanent;

    if ( -e $request_filename ) {
            rewrite ^ - last;
            rewrite ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 last;
            rewrite ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 last;
            rewrite . index.php last;
    }

I have tried it

I built wordpress3.0.1 in virtualbox with apache2, just finding the .htaccess file was shown below:

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

RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]

so the nginx rewrite rule should be those:

location ~ / {
    rewrite ^index\.php$ - last;
    if( !-e $request_filename ) {
        rewrite . /index.php last;
    }
}

and this works!

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