duan4739 2014-12-13 02:06
浏览 69
已采纳

htaccess http到https和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. 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. 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.

I feel this might be over doing it or maybe im just wrong so I figured I would ask to be safe.

  • 写回答

1条回答 默认 最新

  • douke3007 2014-12-13 02:42
    关注

    The rules should be fine, although you can combine the two using the OR flag:

    RewriteCond %{HTTPS} !^on$ [OR]
    RewriteCond %{HTTP_HOST} !^www.domainname.com$ [NC]
    RewriteRule ^(.*)$ https://www.domainname.com/$1 [L,R=301]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口