简体   繁体   English

htaccess http到https和www

[英]htaccess http to https and www

I am going back and forth with this and figured at this point I should ask for opinions/help. 我将对此进行反复研究,并想在这一点上我应该寻求意见/帮助。 I want to redirect people coming into my site that are not using www to the www version as well as change it to https so the whole site is secure from the beginning. 我想将不使用www的进入我网站的用户重定向到www版本,并将其更改为https,以便从一开始就确保整个网站的安全。 I have a cart but since there will be coupons generated with URL links users might be coming in from different areas and I just want to ensure that everything is as secure as I can get it. 我有一个购物车,但是由于会生成通过URL链接生成的优惠券,因此用户可能来自不同地区,我只想确保一切都尽可能安全。 Is this wrong/overkill? 这是错/过度杀伤力吗?

RewriteEngine On
RewriteCond %{HTTPS} !^on$
RewriteRule (.*) https://domainname.com/$1 [R,L]
RewriteCond %{HTTP_HOST} !^www.domainname.com$ [NC]
RewriteRule ^(.*)$ https://www.domainname.com/$1 [L,R=301]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

I also have several links on the site that go to the checkout page as absolute urls with the https in them as well as a php redirect to https located at the top of the checkout page. 我在网站上也有几个链接,这些链接以带有https的绝对URL转到结帐页面,以及指向结帐页面顶部的https的php重定向。

I feel this might be over doing it or maybe im just wrong so I figured I would ask to be safe. 我觉得这样做可能已经结束,或者可能是我做错了,所以我想我要保证安全。

The rules should be fine, although you can combine the two using the OR flag: 这些规则应该很好,尽管您可以使用OR标志将两者结合起来:

RewriteCond %{HTTPS} !^on$ [OR]
RewriteCond %{HTTP_HOST} !^www.domainname.com$ [NC]
RewriteRule ^(.*)$ https://www.domainname.com/$1 [L,R=301]

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

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