douxing9228 2014-10-16 13:43
浏览 38
已采纳

用路由将htaccess重写为https

Im using the following .htaccess for my website. I redirect all urls to index.php if their isn't a file located at the url.

Options +FollowSymLinks
IndexIgnore */*
# Turn on the RewriteEngine
RewriteEngine On
#  Rules
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php

This way http://website.com/user/user_name/ goes to index.php and http://website.com/css/style.css gives the actual css file (if style.css exists).

This works great, only i want to force https:// on the urls and i can't manage to get it to work. Any help is greatly appreciated.

Edit:

Using Jeroen's answer I got it working with the following .htaccess

Options +FollowSymLinks
IndexIgnore */*
# Turn on the RewriteEngine
RewriteEngine On
#  Rules
RewriteCond %{HTTP:CF-Visitor} '"scheme":"http"'
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
  • 写回答

2条回答 默认 最新

  • doudu3961 2014-10-16 14:09
    关注

    As you are using CloudFlare's ssl - I assume Flexible SSL - you need a different solution although @Fox's solution is correct for a "normal" ssl connection.

    For CloudFlare you need something like:

    RewriteCond %{HTTP:CF-Visitor} '"scheme":"http"'
    RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L,QSA]
    

    Also see CloudFlare's support article.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 求数学坐标画圆以及直线的算法
  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决