簡體   English   中英

強制https后,Codeigniter仍顯示index.php

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM