.htaccess:http:// www重定向到www.www [英] .htaccess: http://www redirects to www.www

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

问题描述

我正在尝试使用.htaccess文件解决问题。我发现使用 http://www.example.com 访问我的页面会重定向到 https://www.www.example.com

I'm trying to solve my issue with .htaccess file. I found out that accessing my page with http://www.example.com redirects to https://www.www.example.com.

我尝试了许多.htaccess规则,但无法弄清楚。
我想将http重定向到https,将非www重定向到www。

I have tried numerous .htaccess rules and can't figure it out. I want to redirect http to https and non www to www.

我的.htaccess文件:

My .htaccess file:

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(.*)$  [NC]
RewriteRule (.*) https://www.%1/$1 [R=301,L]

我尝试了单独的规则或倒序(先添加到https,然后添加www),但我仍然得到双倍的www。

I tried separate rules or reversing order (first to https then add www) but I'm still getting double www.

推荐答案

根据您的要求进行编辑。

Edited to work the way you asked.

尝试一下作为您在.htaccess中的配置:

Try this as your configuration in .htaccess:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$
RewriteRule ^(.*)$ https://www.%1%{REQUEST_URI} [R=301,L]

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

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