强制 https 后,Codeigniter 仍然显示 index.php
Codeigniter still shows index.php after forcing https
刚刚使用 SSL 证书启动了我的网站。当我访问 https 站点时,它运行良好。但是,如果我只强制使用 http,即使在配置 htaccess 之后,它也会将我转发到 https 站点,但它会将 index.php?/
添加到 url 的末尾。例如,如果我转到 http://www.my-site.com
,它会重定向到 https://www.my-site.com/index.php?/
。当然,该网站运行良好,只是在 url 字段中有点碍眼。
base_url变量如图:
$config['base_url'] = 'http' . ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 's' : '').'://'.$_SERVER['HTTP_HOST'].str_replace('//','/',dirname($_SERVER['PHP_SELF']).'/');
我的 .htaccess 看起来像这样:
RewriteEngine on
RewriteCond !^(index\.php?|_assets|robots\.txt|sitemap\.xml|favicon\.ico?)
RewriteRule ^(.*)$ /index.php?/ [L]
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
在研究了访问者使用 http 访问网站时如何强制使用 https 后,我添加了最后两行。
我错过了什么? htaccess 不是我的强项。它是共享访问权限,否则我会编辑我的 httpd.conf
编辑:
更新后的 htaccess
看起来像这样:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
这在技术上是可行的,但出于某种原因,当我使用 http
访问该站点时,它会重定向到 https
版本,但将我的 URI 的另一个副本连接到末尾。例如,如果我转到 http://example.com/products
,它会重定向到 https://example.com/products?/products
。
htaccess第三行应该是:
RewriteRule ^(.*)$ index.php/
1. 反正问号(?)不应该出现
2. [L]标志表示最后。应用此规则时,不会运行其他指令。
因此,第五行永远不会运行,但这第五行是从 url.
中删除 index.php 的那一行
刚刚使用 SSL 证书启动了我的网站。当我访问 https 站点时,它运行良好。但是,如果我只强制使用 http,即使在配置 htaccess 之后,它也会将我转发到 https 站点,但它会将 index.php?/
添加到 url 的末尾。例如,如果我转到 http://www.my-site.com
,它会重定向到 https://www.my-site.com/index.php?/
。当然,该网站运行良好,只是在 url 字段中有点碍眼。
base_url变量如图:
$config['base_url'] = 'http' . ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 's' : '').'://'.$_SERVER['HTTP_HOST'].str_replace('//','/',dirname($_SERVER['PHP_SELF']).'/');
我的 .htaccess 看起来像这样:
RewriteEngine on
RewriteCond !^(index\.php?|_assets|robots\.txt|sitemap\.xml|favicon\.ico?)
RewriteRule ^(.*)$ /index.php?/ [L]
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
在研究了访问者使用 http 访问网站时如何强制使用 https 后,我添加了最后两行。
我错过了什么? htaccess 不是我的强项。它是共享访问权限,否则我会编辑我的 httpd.conf
编辑:
更新后的 htaccess
看起来像这样:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
这在技术上是可行的,但出于某种原因,当我使用 http
访问该站点时,它会重定向到 https
版本,但将我的 URI 的另一个副本连接到末尾。例如,如果我转到 http://example.com/products
,它会重定向到 https://example.com/products?/products
。
htaccess第三行应该是:
RewriteRule ^(.*)$ index.php/
1. 反正问号(?)不应该出现
2. [L]标志表示最后。应用此规则时,不会运行其他指令。
因此,第五行永远不会运行,但这第五行是从 url.