2013-03-01 84 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';