【问题标题】:Trailing Slash Issue with WP in a Vagrant Dev EnvironmentVagrant 开发环境中 WP 的尾随斜线问题
【发布时间】:2013-01-30 01:18:21
【问题描述】:

我有一个在 Vagrant 开发环境中运行的 Wordpress 网站。当我加载http://localhost:8080 时,该网站正常运行,但一旦我尝试通过转到http://localhost:8080/wp-admin 来访问管理员,我就会被重定向到http://localhost/wp-admin/

这里有两件事:

  1. 某些东西(Wordpress?)正在强制使用尾部斜杠(这很好,除了...)。
  2. 在尾部斜杠重定向中,端口丢失(这很不正常)。

我尝试添加 port_in_redirect 指令(老实说,使用这两个值),我在其他类似问题的答案中看到过,但它没有任何改变。这似乎是一个 Wordpress,咳咳,功能,但我找不到任何东西来解释它的目的或帮助我防止它破坏东西。我希望有人可以提供帮助。

我的 Nginx server 块:

server {
  listen      80;
  server_name localhost;
  root        /vagrant/www;
  index       index.php;

  access_log /var/log/nginx/project.vm.access.log;
  error_log  /var/log/nginx/project.vm.error.log;

  location / {
    try_files $uri $uri/ /index.php?$args;
  }

  # Add trailing slash to */wp-admin requests so the admin interface
  # works correctly. I've tried with and without this. No difference.
  rewrite /wp-admin$ $scheme://$host$uri/ permanent;

  location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    include fastcgi_params;
  }

  # Cache static files
  location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
    expires max;
    log_not_found off;
  }

  location = /favicon.ico {
    access_log off;
    log_not_found off;
  }
  location = /robots.txt {
    access_log off;
    log_not_found off;
    allow all;
  }

  location ~ /\. {
    access_log off;
    log_not_found off;
    deny all;
  }

  location ~ ~$ {
    access_log off;
    log_not_found off;
    deny all;
  }
}

在我的wp-config.php 文件中,我设置了WP_HOMEWP_SITEURL 常量。

define('WP_HOME','http://localhost:8080');
define('WP_SITEURL','http://localhost:8080');

知道我错过了什么吗?

【问题讨论】:

  • 如果是 Nginx 做的,请尝试在 wp-admin 重写中包含server_portrewrite /wp-admin$ $scheme://$host:$server_port$uri/ permanent;
  • 前几天我试过了。没有喜悦。谢谢。
  • 帮助了我@myanimal。它在官方 WP nginx 文档中codex.wordpress.org/Nginx

标签: wordpress nginx vagrant


【解决方案1】:

我最近在将 WordPress 安装从服务器移动到本地 Vagrant 实例后遇到了同样的问题并解决了它添加:

define('RELOCATE',true);

到 wp-config.php 文件并转到 http://localhost:8080/wp-login.php

我在http://codex.wordpress.org/Changing_The_Site_URL#Relocate_method 找到了解决方案,我认为您可以在那里找到一些其他方法来处理将 WP 安装从一台服务器移动到另一台服务器的问题。

【讨论】:

    猜你喜欢
    • 2017-10-20
    • 1970-01-01
    • 2011-02-11
    • 1970-01-01
    • 2022-08-02
    • 2010-09-14
    • 1970-01-01
    • 2011-01-01
    • 1970-01-01
    相关资源
    最近更新 更多