.htaccess 和 SSL 并重定向到 index.php

标签 .htaccess ssl

<分区>


想改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。

关闭 11 年前

我有这个 .htaccess 文件将所有请求重定向到根目录中的 index.php。

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !.(jpg|jpeg|gif|png|css|js|pl|txt)$
RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^(.*) index.php

现在我想添加以强制将 http 协议(protocol)转换为 https。

我必须如何更改我的文件?

谢谢

最佳答案

如果您想强制所有对您域的请求都是安全的,请将下面的代码添加到您的 .htaccess 文件中。

RewriteEngine On
RewriteBase /

#if the request is not secure
RewriteCond %{HTTPS} off
#redirect to the secure version
RewriteRule (.*) https://%{HTTP_HOST}/$1 [R=301,L]

#These are your existing rules
RewriteCond %{REQUEST_FILENAME} !.(jpg|jpeg|gif|png|css|js|pl|txt)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^(.*) index.php

关于.htaccess 和 SSL 并重定向到 index.php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8625213/

上一篇:c# - 在 C# 中建立 SSL 连接时如何检查无效凭据

下一篇:c# - 使用无效证书解决方法的 WebService 的 SSL 连接不起作用

相关文章:

wordpress - 通配符 ssl .htaccess 文件在 laravel 子域上导致 500 错误

ruby-on-rails - 如何设置本地 SSL 证书和 Rails 应用程序?

ruby-on-rails-3 - 如何创建安全 Controller

ssl - Gitlab-webroot目录

html - 在您的根目录中有一个索引页面是否至关重要,例如 index.html、index.php

apache - SSL WWW 重定向失败

apache - htaccess 域 example.com 中的重定向错误 :443

apache - 一个字符搞乱了 htaccess

java - 使用 Intellij 生成的代码、客户端证书和 session cookie 的 SOAP Webserice。独立工作。不适用于 glassfish 3.1.2.2

ssl - 使用 tcpdump 仅捕获 ssl 握手