用路由将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

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.

Try this

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{HTTPS} off
  RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>