.htaccess-从www https重定向到非www https [英] .htaccess - redirect from www https to non www https

查看:84
本文介绍了.htaccess-从www https重定向到非www https的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有.htaccess:

I have .htaccess:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
RewriteRule ^(.*) http://%1 [R=302,NE,L]

当我从(示例)重定向时,它可以正常工作:从http://重定向到正确的https://从 http://www 重定向到正确的https://但是当我有 https://www 时.我没有重定向和非信任连接".

It works ok when I have redirection from (example): from http:// is redirect to correct https:// from http://www is redirect to correct https:// but when I have https://www. I don't have redirection and "non trusted connection".

我应该在htaccess文件中进行哪些更改?

What I should change in my htaccess file?

推荐答案

也只需在第二条规则上重定向到https,例如

Just redirect to https on your second rule too, e.g.

RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=302,NE,L]

不相关,但是您无需捕获路径,只需使用 REQUEST_URI .

Not related, but you don't need to capture the path, only use REQUEST_URI.

这篇关于.htaccess-从www https重定向到非www https的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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