1
我使用codeigniter與一些URL路由。.htaccess代碼使http轉到https與CodeIgniter併發症
我想從http遷移到https。
這是我目前的.htaccess代碼:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^eternalcitytours\.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^XXX\.XXX\.XXX\.XXX [NC]
RewriteRule ^(.*)$ http://eternalcitytours.com/$1 [R=301,L]
<IfModule mod_rewrite.c>
# Development
RewriteEngine On
RewriteBase/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|scripts|styles|vendor|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
以上可以在HTTP罰款。
要訪問https我改變了.htaccess
是:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule .* https://eternalcitytours.com/%{REQUEST_URI} [R,L]
RewriteEngine On
RewriteCond %{HTTP_HOST} !^eternalcitytours\.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^037\.061\.237\.216 [NC]
RewriteRule ^(.*)$ https://eternalcitytours.com/$1 [R=301,L]
<IfModule mod_rewrite.c>
# Development
RewriteEngine On
RewriteBase/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|scripts|styles|vendor|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
然而,上面的代碼不工作,我得到兩個問題:
- 每當傳入流量來自於我從HTTP鏈接,結果網址有一個額外的/在它:例如https://eternalcitytours.com//en/5/About-Eternal-City-Tours而不是https://eternalcitytours.com/en/5/About-Eternal-City-Tours
- 如果有人有https://WWW.eternalcitytours.com那麼頁面將不會加載並給出錯誤。 (
ERR_SSL_PROTOCOL_ERROR
)
有人可以幫助我的.htaccess代碼,因爲我老實說不知道我在做什麼。
感謝
嗨anabhava,問題1解決了。謝謝。就概率2而言,儘管對於人們嘗試通過https://eternalcitytours.com/...來訪問我的網站時,我有同樣的問題,因爲SSL證書期望WWW https://WWW.eternalcitytours。 com? –
沒關係 - 我在SSL握手之前發生的DNS記錄級別上找到了它。我還遇到的另一個問題是,我使用了CloudFlare,它改變了一切,現在我已禁用。謝謝 –