本文介绍了如何从WWW重定向到HTTPS WWW与htacces?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要做到以下几点:
我现在的地址如下所示:

I need to do the following:My current address looks like: https://www.domain.com

我想与htaccess的重定向:
www.domain.com至并
来的

I want to redirect with htaccess:www.domain.com TO https://www.domain.com andhttp://domain.com TO https://www.domain.com

我试着在这里提出一些建议,但它结束了无休止的循环。
我想:

I've tried with some suggestions here, but it ended up with the endless loop.I tried:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.domain.com [NC]
RewriteRule ^(.*)$ https://www.domain.com/$1 [L,R=301]

任何帮助将是AP preciated。

Any help would be appreciated.

更新:我想我已经用下面的做到了:

UPDATE: I think I've done it with the following:

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [R=301,L]

这是正确的方式做到这一点?

Is that the right way to do it?

推荐答案

您应该有一个 盈的域名状态:

You should have a ! infront of your domain name condition:

### Redirect non-www => www ###
RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
RewriteRule ^(.*)$ https://www.domain.com/$1 [L,R=301]

由于你想说的,做下一个规则,如果这个条件匹配...和条件应该是主机确实不会匹配你想要的东西。

Because you want to say, do the next rule, if this condition matches... and the condition should be host does NOT match what you want.

如果我的技术我已经看到和之前使用混合,你可以试试这个:

If i mix this with techniques i have seen and used before, you could try this:

### Redirect non-www => www ###
RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
RewriteRule ^(.*)$ https://www.domain.com/$1 [L,R=301]

# redirect urls with index.html to folder
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index.html HTTP/
RewriteRule ^(([^/]+/)*)index.html$ https://%{HTTP_HOST}/$1 [R=301,L]

# change // to /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)//(.*) HTTP/ [NC]
RewriteRule ^.*$ https://%{HTTP_HOST}/%1/%2 [R=301,L]

这篇关于如何从WWW重定向到HTTPS WWW与htacces?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 17:40