nginx重写index.php,nginx /index.html到/重写

我正在尝试将/index.html重写为/用于搜索引擎优化目的(愚蠢的搜索引擎混淆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(已注释掉的部分是我最近的尝试 – 当取消注释时,当您尝试访问www.domain.com/index.html时,它会发出301 Moved Permanently错误):

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;

}

cobaco解决方案的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://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;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值