我为我的网站使用以下 .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 存在)。
这很好用,只是我想在 url 上强制使用 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 - 我假设是 Flexible SSL - 尽管@Fox 的解决方案对于“正常”ssl 连接是正确的,但您需要一个不同的解决方案。
对于 CloudFlare,您需要这样的东西:
RewriteCond %{HTTP:CF-Visitor} '"scheme":"http"'
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L,QSA]
关于php - 使用路由将 htaccess 重写为 https,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26406001/