如何将HTTP重定向到https和https:// WWW到https://如何将、重定向、WWW、HTTP

2023-09-02 00:56:39 作者:仙女界扛把子

我需要重写规则帮助。

所以,我想,这些地址:

  http://domain.com
http://www.domain.com
https://www.domain.com
 

跳转到:

  https://domain.com
 

有人能帮助我吗?

现在我有规则:

 的RewriteCond%{} SERVER_PORT 80
重写规则^(。*)$ https://domain.com/$1 [R,L]

但它不重定向https://开头WWW到https://
 
设置IIS7 http重定向到https

解决方案

将在 DOCUMENT_ROOT /的.htaccess 文件的规则:

  RewriteEngine叙述上

的RewriteCond%{} HTTPS关闭[OR]
的RewriteCond%{HTTP_HOST} WWW 。
重写规则^的https://domain.com% {REQUEST_URI} [L,R = 301,NE]
 

I need help with rewrite rules.

So I want that these addresses:

http://domain.com
http://www.domain.com
https://www.domain.com

Redirect to:

https://domain.com

Can someone help me?

Right now I have rule:

RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://domain.com/$1 [R,L]

But it doesnt redirect https://www to https://

解决方案

Place this rule in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} www.
RewriteRule ^ https://domain.com%{REQUEST_URI} [L,R=301,NE]