伪静态 - Typecho强制Https且带www跳转到不带www

查看:288
本文介绍了伪静态 - Typecho强制Https且带www跳转到不带www的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

博客使用OneinStack一键包搭建,也开启了强制Https访问,目前不带www的域名访问都正常的(博客本身绑定的也是这个域名),但带www的域名访问时,会跳404错误,具体为地址栏上显示为:https://uu126.cn//index.php,多了一个/,如果有打开文章页面的,比如:https"//www.uu126.cn/post/2400.html"会直接跳转到首面,而不是继续显示后面的路径。因为OneinStack的主机配置文件里是嵌套了Typecho伪静态规则文件,如果直接将伪静态规则直接写在主机配置文件里,重启Nginx 后可以解决标题上写的功能(强制Https且带www跳转到不带www),但是也有弊端,会出现后台拒绝访问的现象,还请各位大侠赐教,附上主机配置文件(含伪静态规则):
server {
listen 80;
listen 443 ssl http2;
ssl_certificate /usr/local/ssl/uu126.pem;
ssl_certificate_key /usr/local/ssl/uu126.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
ssl_prefer_server_ciphers on;
ssl_session_timeout 10m;
ssl_session_cache builtin:1000 shared:SSL:10m;
ssl_buffer_size 1400;
add_header Strict-Transport-Security max-age=15768000;
ssl_stapling on;
ssl_stapling_verify on;
server_name uu126.cn www.uu126.cn;
access_log off;
index index.html index.htm index.php;

root /data/www/uu126.cn;
if ($ssl_protocol = "") { return 301 https://$host$request_uri; }
#error_page 404 = /404.html;
#error_page 502 = /502.html;
if ($host != uu126.cn) {

rewrite ^/(.*)$ $scheme://uu126.cn/$1 permanent;

}

location ~ 1.php(/|$) {

#fastcgi_pass remote_php_ip:9000;
fastcgi_pass unix:/dev/shm/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;

}
location ~ .*.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {

expires 30d;
access_log off;

}
location ~ .*.(js|css)?$ {

expires 7d;
access_log off;

}
location ~ /.ht {

deny all;

}
location / {

    index index.html index.php;
    if (-f $request_filename/index.html){
        rewrite (.*) $1/index.html break;
    }
    if (-f $request_filename/index.php){
        rewrite (.*) $1/index.php;
    }
    if (!-f $request_filename){
        rewrite (.*) /index.php;
    }
}

}


  1. /

解决方案

我也是用的这个一键包,你的排版比较乱,给你参考一下我的:

include /usr/local/nginx/conf/typecho.conf;#typecho重写规则(自带)

if ($ssl_protocol = "") {
    return 301 https://$server_name$request_uri; 
} 

if ($host != 'uu126.cn' ) {
    return 301 https://uu126.cn$request_uri; 
} 

这篇关于伪静态 - Typecho强制Https且带www跳转到不带www的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆