简体   繁体   English

使用.htaccess将http://www.domain.com重定向到https://www.domain.com

[英]Redirect http://www.domain.com to https://www.domain.com using .htaccess

I want to redirect my domain from http to https: 我想将我的域从http重定向到https:

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

Is it possible? 可能吗? I've been searching around the internet but I only found: 我一直在互联网上搜索,但只发现:

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

The question is, how about peoples arriving directly on http://www.domain.com ? 问题是,人们如何直接到达http://www.domain.com Aren't they be served with non-https url? 他们不是通过非https网址投放吗? Same as the vice versa. 反之亦然。 I just want a simple redirection from the HTTP to HTTPS. 我只想简单地从HTTP重定向到HTTPS。 Is it possible? 可能吗?

Thank you 谢谢

I just want a simple redirection from the HTTP to HTTPS

Try this simple rule as first rule on your .htaccess : 尝试将此简单规则作为您的.htaccess的第一条规则

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

Use the following code for force www and SSL usage: 使用以下代码强制使用www和SSL:

RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

It will work for ALL versions of php and will force SSL and www to all naked domains and links: 它将适用于所有版本的php,并将SSL和www强制应用于所有裸域和链接:

RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS} off
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
  • We DO need the NE 我们确实需要NE
  • www. 万维网。 is optional in 4th line 在第四行是可选的
  • "off" is required to be. 必须为“ off”。

 <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{HTTPS} off # Now, rewrite any request to the wrong domain to use www. RewriteCond %{HTTP_HOST} !^www\\. RewriteCond %{HTTP_HOST} ^tatwerat\\.com [NC] RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} </IfModule> 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将http://www.domain.com重定向到https://domain.com - redirect http://www.domain.com to https://domain.com .htaccess-将domain.com和www.domain.com重定向到www.domain.com/en - .htaccess - redirect domain.com and www.domain.com - to www.domain.com/en 如何使用.htaccess通过HTTP和HTTPS将传入请求从domain.com重定向到www.domain.com? - How do I redirect incoming requests from domain.com to www.domain.com via HTTP and HTTPS using .htaccess? htaccess重定向规则从www.domain.com/?page=news到www.domain.com/news - htaccess redirect rule from www.domain.com/?page=news to www.domain.com/news 如何使用htaccess将www.domain.com/subfolder/重定向到www.domain.com/subfolder/blog.html - How to redirect www.domain.com/subfolder/ to www.domain.com/subfolder/blog.html using htaccess SSL错误:如何通过.htaccess将https://www.domain.com重定向到http://domain.com以避免SSL错误 - SSL Error: how to redirect https://www.domain.com to http://domain.com via .htaccess to avoid SSL error http to https AND //domain.com to www.domain.com AND subdomain.domain.com to subdomain.domain.com through htaccess - http to https AND //domain.com to www.domain.com AND subdomain.domain.com to subdomain.domain.com through htaccess 将 https://domain.com 重定向到 https://www.domain.com - redirecting https://domain.com to https://www.domain.com htaccess将domain.com重定向到www.domain.com,但多个域的staging.domain.com除外 - htaccess redirect domain.com to www.domain.com except of staging.domain.com for multiple domains 使htaccess接受domain.com和www.domain.com - Make htaccess accept domain.com and www.domain.com
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM