2016-08-15 145 views
0

我使用codeigniter框架,設置.htaccess文件刪除index.php並嘗試啓用服務器的HTTPS協議,併發生了一些事情。HTTPS和刪除CodeIgniter的index.php

HTTP:

  1. 一切進展順利,當我訪問http://www.example.com/controller/methodhttp://www.example.com/index.php/controller/method

HTTPS:

  1. 一切進展順利,當我訪問https://www.example.com/的index.php /控制器/方法

  2. 了404,當我訪問https://www.example.com/controller/method

我認爲這是.htaccess文件的問題沒有發現,它是看起來像htaccess文件無法正常工作的HTTPS協議。

.htaccess文件我的網站。

DirectoryIndex index.php 
RewriteEngine on 

RewriteCond %{HTTPS} off 
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 

RewriteCond $1 !^(index\.php|(.*)\.swf|forums|images|css|downloads|js|robots\.txt|favicon\.ico) 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ ./index.php?$1 [L,QSA] 

有什麼不對嗎?非常感謝。

+0

只要檢查一下,你是否確定你的文件名正確,哪裏只有文件名和類的第一個字母是大寫。 – user4419336

+0

@ wolfgang1983文件名是正確的,當通過HTTP協議訪問網站時一切正常,但在通過HTTPS協議訪問網站時不起作用,它看起來像.htaccess文件不適用於HTTPS協議。 –

回答

0

首先你刪除$配置[「BASE_URL]從您的配置文件,並把‘’(空白)在$配置[」指數']屬性..

請設置您的.htaccess文件如..

<IfModule mod_rewrite.c> 
RewriteEngine On 

    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 

    # Rewrite all other URLs to index.php/URL 
    RewriteRule ^(.*)$ index.php?url=$1 [PT,L] 
    </IfModule> 
    <IfModule !mod_rewrite.c> 
     ErrorDocument 404 index.php 
    </IfModule> 
+0

對不起,它僅適用於http,仍然不適用於https協議。 –

0

試試這個

我在我的項目之一使用這一點。可在其幫助您

#AuthType Basic 
#AuthName "restricted area" 
#AuthUserFile /home/site_name/public_html/.htpasswd 
#require valid-user 

RewriteEngine On 
#RewriteBase/

RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.site_name.com/$1 [R,L] 

RewriteCond %{HTTP_HOST} ^([a-z.]+)?.site_name.lk$ [NC] 
RewriteRule ^(.*)$ https://www.site_name.com/$1 [R=301,L] 

RewriteCond %{HTTP_HOST} ^([a-z.]+)?site_name\.com$ [NC] 
RewriteCond %{HTTP_HOST} !^www\. [NC] 
RewriteRule .? https://www.%1site_name.com%{REQUEST_URI} [R=301,L] 

<IfModule mod_rewrite.c> 
    RewriteEngine on 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
# RewriteCond $1 !^(index\.php|assets|files|robots\.txt) 
# RewriteRule ^(.*)$ /index.php/$1 [L] 

    RewriteRule ^(.*)$ index.php/$1 [L,QSA] 
</IfModule> 

注意site_name在上面htaccess的應更換,以你的網站名稱

+0

仍然不工作=( –

0

你可以試試這個,它適合我的項目。

RewriteEngine On 
RewriteCond %{HTTPS} !=on 
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L] 

RewriteCond $1 !^(index\.php|(.*)\.swf|forums|images|css|downloads|js|robots\.txt|favicon\.ico) 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php/$1 [L,QSA] 

參考:https://wiki.apache.org/httpd/RewriteHTTPToHTTPS

0

注:SSL重寫應該在你的.htaccess文件index.php重寫之前發生。

所以,不要做這個設置(因爲我們不會改變服務器的apache配置文件中的任何東西。 )

的AllowOverride所有

只是應用設置2它的工作原理。


我都面臨着同樣的問題,並通過添加

的AllowOverride所有

設置1解決它: 僅供參考,我們有2個配置文件。

  1. 默認的Apache配置(與HTTP運行)
  2. SSL配置(與HTTPS運行)

轉至SSL配置,並添加

<Directory "/var/www/html"> 
    AllowOverride All 
</Directory> 

**設置2: ** .htaccess文件應該是這樣的...

RewriteEngine On 
RewriteCond %{HTTPS} !=on  
RewriteRule^https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 

<IfModule mod_rewrite.c> 
    RewriteEngine on 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule^index.php [L] 
</IfModule> 

它爲我工作。