htaccess重定向到“ https:// www”。 [英] htaccess redirect to "https://www."

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

问题描述

我想重定向到 https:// www

这意味着

http:// --> https://www.
http://www. --> https://www.
https:// --> https://www.
https://www. --> no redirection

我尝试了很多事情,但从未达到目标。

I tried plenty of things but never reached that goal.

我当前的 .htacces

my current .htacces:

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteCond %{HTTP:X-Forwarded-Proto} =http
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ web/$1 [QSA,L]
</IfModule>

但是问题在于它不会重定向到 www 。因此,我尝试将其放在前面:

But the problem is that it doesn't redirect to www. So I tried to put that before :

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

但这使重定向卷曲,因此关闭了我的网站。

But that made a redirection curl so shut my site down.

PS:我正在使用symfony

PS: I'm on symfony

有人有神奇的解决方案吗?
谢谢!

Does someone have the magic solution ? Thank's !

推荐答案

您可以使用这些规则来强制执行 https和 www`:

You can use these rules to enforce both https andwww`:

RewriteCond %{HTTP_HOST} !^www\. [OR,NC]
RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [L,R=301,NE]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ web/$1 [L]

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

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