2016-08-15 142 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> 

它为我工作。