【问题标题】:wordpress nginx redirect folderwordpress nginx重定向文件夹
【发布时间】:2016-11-07 20:17:00
【问题描述】:

好人! :)

我已将网站(WordPress 网站)迁移到另一台服务器。 wordpress 最初安装在 domain.com/site/ 中,它有一个索引文件将用户重定向到 /site/。 现在 WP 安装在根文件夹 (domain.com/) 中。 我需要向 domain.com/site/?p=x 提出每个请求去 domain.com/?p=x 我一直在寻找很多位置规则,但我无法让它发挥作用。我能做的最好的就是从 domain.com/site/?p=x 重定向到 domain.com/site?p=x,显然这会给出 404。
该网站所在的服务器是apache。现在在新服务器中我使用 nginx。 我用easyengine安装了nginx、php-fpm、mysql。使用 w3tc 插件创建了一个 wordpress 网站。

有人可以帮助我吗? 谢谢

【问题讨论】:

    标签: wordpress redirect nginx nginx-location


    【解决方案1】:

    好问题!

    Nginx 是一个不错的选择,请在您的nginx.conf 中执行此操作:

    location /site {
        rewrite ^/site/?((?<=/).*)?$    /$1 redirect;
        return  403;
    }
    

    (?&lt;= 部分是一个lookbehind assertion,根据pcrepattern(3),它来自pcre 库,Apache httpdnginx 都使用它来支持正则表达式。

    return 403; 是必要的,以防所写的正则表达式存在安全问题(例如,如果它无法提供重定向)。

    【讨论】:

    • 谢谢cnst! :)
    猜你喜欢
    • 2013-08-20
    • 2014-09-02
    • 2017-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-29
    • 2016-10-02
    相关资源
    最近更新 更多