[英]Forcing HTTPS with www and remove index.php .htaccess in CodeIgniter
[英]Codeigniter still shows index.php after forcing https
剛剛使用SSL證書啟動了我的網站。 當我轉到https站點時,它運行良好。 但是,即使配置了htaccess之后,如果我僅強制使用http,它也會將我轉發到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
。
htaccess的第三行應為:
RewriteRule ^(.*)$ index.php/$1
1.無論如何,問號(?)不應存在。
2. [L]標志表示最后。 當應用此規則時,將不運行其他指令。
因此,第五行永遠不會運行,但是第五行是從URL中刪除index.php的那一行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.