[英]rewrite htaccess to https with route
我在我的网站上使用以下.htaccess文件。 如果不是位于URL的文件,我会将所有URL重定向到index.php。
Options +FollowSymLinks
IndexIgnore */*
# Turn on the RewriteEngine
RewriteEngine On
# Rules
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
这样, http: //website.com/user/user_name/转到index.php,而http://website.com/css/style.css提供了实际的CSS文件(如果存在style.css)。
这很好用,只有我想在网址上强制使用https://,而我却无法使其正常工作。 任何帮助是极大的赞赏。
编辑:
使用Jeroen的答案,我将其与以下.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
当您使用CloudFlare的ssl(我假设使用灵活SSL)时,尽管@Fox的解决方案对于“正常” ssl连接是正确的,但您需要其他解决方案。
对于CloudFlare,您需要以下内容:
RewriteCond %{HTTP:CF-Visitor} '"scheme":"http"'
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L,QSA]
另请参阅CloudFlare的支持文章 。
尝试这个
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.