我想重写/index.html /为SEO目的(愚蠢的搜索引擎混淆了index.html /和处罚重复的内容) - 也协调网站分析数据。nginx /index.html改写/重写
我试过了我在stackoverflow,nginx文档等找到的每个解决方案,都没有成功。我想我必须有一些其他配置问题或其他痛苦明显的问题。这是我的第一个nginx安装 - 用于Apache和IIS!
这里是我的default.conf:
server {
listen 80;
server_name web.local;
#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
这里是我的virtual.conf(注释部分是我最近一次尝试 - 未注释时,它提供一个301永久移动,当您试图访问WWW错误.domain.com/index.html中):
server {
listen 80;
server_name www.domain.com;
location/{
root /var/www/html/domain.com;
index index.html;
#if ($request_uri = /index.html) {
# rewrite^http://www.domain.com permanent;
#}
}
}
server {
listen 80;
server_name domain.com;
rewrite ^/(.*) http://www.domain.com/$1 permanent;
}
HTTP响应头为cobaco的溶液:
URL:
http://www.domain.com
http/1.1 301 moved permanently
server: nginx/1.2.8
date: Thu, 16 May 2013 01:42:58 GMT
content-type: text/html
content-length: 184
connection: keep-alive
location: http://domain.com/
Redirecting URL:
http://domain.com/
http/1.1 301 moved permanently
server: nginx/1.2.8
date: Thu, 16 May 2013 01:42:58 GMT
content-type: text/html
content-length: 184
connection: keep-alive
location: http://www.domain.com/
我想这条线可能会导致问题:“location = /index.html {return 301 $ scheme://domain.com/;}”所以我添加了www。在“scheme://”之后 - 让我知道这是不是一件坏事!这导致了以下HTTP响应头:
URL:
http://www.domain.com
http/1.1 301 moved permanently
server: nginx/1.2.8
date: Thu, 16 May 2013 01:42:58 GMT
content-type: text/html
content-length: 184
connection: keep-alive
location: http://www.domain.com/
Redirecting URL:
http://www.domain.com/
http/1.1 301 moved permanently
server: nginx/1.2.8
date: Thu, 16 May 2013 01:42:58 GMT
content-type: text/html
content-length: 184
connection: keep-alive
location: http://www.domain.com/
一些修修补补后,下面的配置做什么,我希望它做的,但并不理想,由于if语句。有什么建议么?
server {
server_name www.domain.com;
root /var/www/html/domain.com;
index index.html;
if ($request_uri = /index.html) {
return 301 http://www.domain.com/;
}
#location = /index.html {
# return 301 $scheme://www.domain.com/;
#}
}
server {
listen 80;
server_name domain.com;
return 301 $scheme://www.domain.com$request_uri;
}
谢谢,很高兴它的作品没关系! :) – auralsun 2013-05-17 00:12:57