htaccess使用index.php重定向到https

eri*_*hak 3 apache .htaccess mod-rewrite codeigniter

嘿,我正在使用codeigniter并添加了重写规则,以index.php从网址中删除工作正常.

但是,我添加了一个规则来将所有http请求重定向到https,但是当它执行时,它会重新定向index.php.

这意味着如果我输入此网址: domain.com/somecoolcontroler

它会将我重定向到: https://domain.com/index.php/somecoolcontroler

但是在之后导航它没有它回到正常的网址所以我想问题是在重定向规则,这是我放在htaccess中:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L] 
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
Run Code Online (Sandbox Code Playgroud)

我该如何解决这个问题?

Jon*_*Lin 5

您需要路由规则之前放置重定向规则.重写引擎循环,所以即使你有L标志,它也会第二次循环遍历你的路由规则并点击重定向规则,除了这次,URI已经被重写了.

如果重写规则是第一个,它将在应用路由规则之前重定向浏览器.然后,当进行重定向的请求时,应用路由规则.你还需要L一面旗帜.

RewriteEngine On

RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L] 
Run Code Online (Sandbox Code Playgroud)