【发布时间】:2018-10-15 22:01:09
【问题描述】:
刚刚使用 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 $1 !^(index\.php?|_assets|robots\.txt|sitemap\.xml|favicon\.ico?)
RewriteRule ^(.*)$ /index.php?/$1 [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?/$1
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
这在技术上是可行的,但由于某种原因,当我使用 http 访问该站点时,它会重定向到 https 版本,但会将我的 URI 的另一个副本连接到末尾。例如,如果我转到http://example.com/products,它会重定向到https://example.com/products?/products。
【问题讨论】:
-
$config['index_page'] ?
-
$config['index_page'] = '';
标签: php .htaccess codeigniter https base-url