Gen*_*ill 1 php apache .htaccess mod-rewrite codeigniter
我正在使用 codeigniter 框架,设置 .htaccess 文件以删除 index.php 并尝试为服务器启用 HTTPS 协议,但发生了一些事情。
HTTP:
HTTPS:
一切都是好的,当我访问https://www.example.com/的index.php /控制器/方法
我认为这是 .htaccess 文件问题,看起来 htaccess 文件不适用于 HTTPS 协议。
我网站的 .htaccess 文件。
DirectoryIndex index.php
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond $1 !^(index\.php|(.*)\.swf|forums|images|css|downloads|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php?$1 [L,QSA]
Run Code Online (Sandbox Code Playgroud)
有什么问题吗?多谢。
小智 7
注意:SSL 重写应该index.php
在.htaccess
文件中的重写之前发生。
因此,不要进行此设置(因为我们不会更改服务器 apache 配置文件中的任何内容。)
允许覆盖所有
只需应用设置 2 即可。
我遇到了同样的问题并通过添加解决了它
允许覆盖所有
设置 1: 仅供参考,我们有 2 个配置文件。
转到 SSL 配置并添加
<Directory "/var/www/html">
AllowOverride All
</Directory>
Run Code Online (Sandbox Code Playgroud)
**设置2:**.htaccess文件应该是这样的...
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]
</IfModule>
Run Code Online (Sandbox Code Playgroud)
它对我有用。