【发布时间】:2015-06-15 11:52:56
【问题描述】:
我需要一个基本的重定向规则,所以如果有人键入:www.site.com 将被重定向到 site.com。我需要它在浏览器中看起来整洁干净。
我在我的 nginx 服务器块中试过这个:
# trying redirects from http:// www.site.com to http:// site.com
if ($host = "www.site.com") {
rewrite ^ $scheme://site.com$uri permanent;
}
...
location / {
try_files $uri $uri/ @modx-rewrite /index.php?/$request_uri;
location ~ .php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
但由于某种原因,它不起作用,我得到“找不到服务器错误”。 它还在我的地址中添加了 http S。
如果没有这些规则,我的网站可以正常打开并通过 https 运行,并且页面可以正常打开 https://site.com 链接。
谢谢。
注意:我故意在地址的代码片段中添加了几个空格,否则 stackoverflow 不会让我发布它。
【问题讨论】: