我想重寫/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