提前感谢您提供的任何帮助。
<小时>Configuration:
Debian Jessie前端Nginx(1个服务器,2个服务器名称;重写工作正常),
代理后端Apache,无重写/别名和其他,WordPress安装在/var/www/www.test.blog/wordpress/
如果没有插件,则中没有声明常量wp-config.php
.
Task:我正在尝试从多个GET URL解析WP:
test.blog
和
www.test.blog
.
由于Apache日志,在请求到达之前,一切正常/var/www/www.test.blog/wordpress/index.php
(第18行),之后突然出现响应301test.blog
(行:19)
01:Request received from client: GET /wordpress/ HTTP/1.0
02:Headers received from client:
03:X-Real-IP: 10.0.2.2
04:X-Forwarded-For: 10.0.2.2
05:Host: www.test.blog
06:Connection: close
07:User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36
08:Upgrade-Insecure-Requests: 1
09:Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng
10:DNT: 1
11:Accept-Encoding: gzip, deflate
12:Accept-Language: ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7
13:authorization result of Require all granted: granted
14:authorization result of <RequireAny>: granted
15:request authorized without authentication by access_checker_ex hook: /wordpress/
16:authorization result of Require all granted: granted
17:authorization result of <RequireAny>: granted
18:request authorized without authentication by access_checker_ex hook: /wordpress/index.php
19:Response sent with status 301, headers:
20:Date: Fri, 26 Jan 2018 14:20:49 GMT
21:Server: Apache/2.4.10 (Debian)
22:Location: http://test.blog/wordpress/
23:Content-Length: 0
24:Connection: close
25:Content-Type: text/html; charset=UTF-8
<小时>
Question:如果,我应该如何阻止这种行为&;finally 是否从多个URL解析?
最合适的回答,由SO网友:swissspidy 整理而成
听起来您博客的主页URL和网站URL都设置为http://test.blog
, 而您的服务器同时接受http://test.blog
和http://www.test.blog
.
如果您访问后者,WordPress会因为不匹配而重定向您。您可以在wp-config.php
像这样:
define( \'WP_SITEURL\', \'https://\' . $_SERVER[\'HTTP_HOST\'] );
define( \'WP_HOME\', \'https://\' . $_SERVER[\'HTTP_HOST\'] );
这样,就不应该有重定向。但这对于帖子内容中的URL之类的东西来说当然很复杂。WordPress
does not use relative URLs for that. 这就是为什么通常最好解决一个1域。但也有其他原因,如SEO(重复内容)。您的web服务器应该重定向www.test。要测试的博客。博客或反之亦然,这是解决这个问题的最简单方法。该网站显然仍然可以通过任何一个主机访问,只是你必须满足于一个主机。
注:$_SERVER[\'HTTP_HOST\']
未在命令行上设置,因此如果要使用WP-CLI,则必须设置该变量。
如果这回答了你的问题,或者我误解了你,请告诉我。