2013-03-01 86 views
0

.htaccess文件是:如何删除index.php并在CodeIgniter URL中添加www?

RewriteEngine on 

RewriteCond $1 !^(index\.php|resources|robots\.txt|img/|css/|js) 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ /index.php/$1 [L,QSA] 

这将删除URL index.php和部队从example.netwww.example.net重定向,但是当我进入http://example.net,它不重定向到www.example.net。如何解决这个问题?

回答

0

设置你的htaccess

Options +FollowSymLinks +ExecCGI 

<IfModule mod_rewrite.c> 
    RewriteEngine On 
    #RewriteBase/

    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteRule^index.php [QSA,L] 
</IfModule> 

删除的index.php在你的配置

$config['index_page'] = ''; 

也让压倒一切的htaccess在Apache

nano /etc/apache2/sites-available/default 

,改变

 AllowOverride All 

,并重新启动Apache

+0

替换以下变量不为我工作 – 2013-03-01 11:14:45

1

在.htaccess文件更改此

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

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

和配置文件作出修改2:

$config['base_url'] = 'http://'.$_SERVER['SERVER_NAME'].'/CiFolderName'; 
$config['index_page'] = ''; 
0

有the.htaccess文件在应用程序的根目录中与index.php文件。 (检查htaccess的扩展名是正确的,BZ htaccess.txt并没有为我工作。)

,并添加以下规则.htaccess文件,

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php/$1 [L] 

然后找到你的应用程序下面的行/ config/config.php文件

$config['index_page'] = 'index.php'; 

将变量设置为空,如下所示。

$config['index_page'] = ''; 

就是这样,它为我工作。

如果没有进一步的工作,尝试用这些参数( 'AUTO', 'PATH_INFO', 'QUERY_STRING', 'REQUEST_URI' 和 'ORIG_PATH_INFO')逐一

$config['uri_protocol'] = 'AUTO';