简体   繁体   English

使用.htaccess从https://重定向到https:// www

[英]Redirect from https:// to https://www using .htaccess

I am trying to get my site to redirect all traffic to https://www.mylittleblackebook.com no matter how the URL is typed into the browser. 我试图让我的网站将所有流量都重定向到https://www.mylittleblackebook.com,无论在浏览器中如何键入URL。 There are six ways someone can type the URL into a browser. 有人可以通过六种方式在浏览器中键入URL。 They are: 他们是:

  1. https://www.mylittleblackebook.com https://www.mylittleblackebook.com
  2. https://mylittleblackebook.com https://mylittleblackebook.com
  3. http://www.mylittleblackebook.com http://www.mylittleblackebook.com
  4. http://mylittleblackebook.com http://mylittleblackebook.com
  5. www.mylittleblackebook.com www.mylittleblackebook.com
  6. mylittleblackebook.com mylittleblackebook.com

All of these URL's will work EXCEPT FOR the second one. 第二个URL以外,所有这些URL都将起作用。 I cannot get the .htaccess file to redirect https:/mylittleblackebook.com to https://www.mylittleblackebook.com . 我无法获取.htaccess文件来将https:/mylittleblackebook.com重定向到https://www.mylittleblackebook.com Here is the code in my .htaccess file: 这是我的.htaccess文件中的代码:

RewriteEngine on

# require SSL without mod_ssl
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTPS} !on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

This code works for 5 out of the 6 ways. 该代码在6种方法中的5种有效。 Can anyone tell me how to get it to work for all of them? 谁能告诉我如何使其对所有人适用?

Thank you for taking the time to look this over. 感谢您抽出宝贵的时间对此进行检查。

Your code looks correct, not sure why it doesn't work. 您的代码看起来正确,不确定为什么不起作用。 I would try this instead, it's in the opposite order and a bit different: 我会尝试这样做,它的顺序相反,有些不同:

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/?(.*) https://www.%{HTTP_HOST}/$1 [L,R,NE] 

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM