php - Wordpress 中的永久链接不适用于 Laravel + Nginx

标签 php wordpress laravel nginx

我在我的主要路线上有一个使用 Laravel 开发的网站,例如 www.example.com/。我已经使用 Nginx 和 php-fpm 正确配置了它。我的配置如下。

然后我在路由 /blog (www.example.com/blog/) 中添加了一个博客,并使用 Nginx alias 配置了它。

现在的问题是 WordPress 中的永久链接不起作用。 Nginx 重定向到 Laravel 的 404 页面。

例如,当用户输入如下 URL:example.com/blog/about 时,Laravel 的 404 页面会显示,这很奇怪。

我该如何解决这个问题?如何配置 Nginx?怎么了?

server {
    listen       80;
    server_name  example.com;
    root /usr/share/nginx/html/;

    location /blog {
        try_files $uri $uri/ /index.php?$args;
        alias /usr/share/nginx/blog/;
        index  index.php index.html index.htm;

        location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            include        fastcgi_params;
            fastcgi_param  SCRIPT_FILENAME   /usr/share/nginx$fastcgi_script_name;
        }
    }

    location / {
        root   /usr/share/nginx/main_site;
        index  index.php index.html index.htm;

        try_files $uri $uri/ /index.php$is_args$args;

        location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    }
}

最佳答案

位置与别名路径的末尾匹配时,您不需要使用别名。请参阅this document .

location/blog 中的 try_files 需要默认为 WordPress 路由器 (/blog/index.php),而不是 Laravel 路由器(/index.php)。

尝试:

location /blog {
    try_files $uri $uri/ /blog/index.php?$args;
    root /usr/share/nginx;
    ...

    location ~ \.php$ {
        ...
        fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;
    }
}

关于php - Wordpress 中的永久链接不适用于 Laravel + Nginx,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35279010/

相关文章:

php - 如何在 PHP/MySQL 中存储生日和年龄以便年龄可以每天更新?

php - 使用 PHPUnit 生成代码覆盖率报告

php - Laravel Eloquent 关系无 key

php - CSRF token 不匹配 Laravel ajax 删除数据

php - Laravel 将外键添加到表中

php - 菜鸟: display err_msg on page (pt. 2)

php - 将 MYSQL 数据库的行转换为列

css - 为什么我的 wordpress 页面的 CSS 在 IE 中不能正常工作,但是当应用于非 wordpress 静态页面时在 IE 中工作正常?

wordpress - 站点地图不工作

wordpress - 来自外部客户端应用程序的 WordPress RESTful 服务的基本身份验证