douye9175 2017-03-06 13:34
浏览 99

Nginx没有将www重定向到www

So I a website which i cant reveal the url to at the moment. So i will refer to it as www.example.com for this question.

I want any attempt to get to my site to redirect to HTTPS:://www.example.com. However this is not the case. I have managed to get it working with redirecting http to https.

If i go to example.com it does redirect to www.example.com, but if i try any other route such as example.com/videos it just redirects to https://example.com/videos instead of https://www.example.com.

Here is my nginx config file:

server{

    listen 80;
    server_name example.com www.example.com;
    rewrite ^/(.*) https://www.example.com/$1 permanent;
}

server {
    listen 443 ssl;

    server_name example.com www.thevirtualpornwebsite.com;
    root /var/www/example_folder/public;


    index index.php index.html index.htm index.nginx-debian.html;


    ssl_certificate /home/example_user/example.com.chained.crt;
    ssl_certificate_key /home/example_user/example.com.key;

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;
    ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';


    location / {
        rewrite ^/(.*)/$ /$1 permanent;
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }
}

If anyone could help out that would be great!

  • 写回答

1条回答 默认 最新

  • duanji1026 2017-03-06 14:33
    关注

    If you check your HTTP server configuration you should see a rewrite rule

    rewrite ^/(.*) https://www.example.com/$1 permanent;
    

    This basically matches any given URL and this match is afterwards passed to the new location as the parameter $1 (check regular expressions).

    If you remove this parameter, you should accomplish what you want:

    rewrite ^/.* https://www.example.com/ permanent;
    
    评论

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大