2014-03-01 276 views
0

如何刪除Codeigniter url中的index.php?刪除Codeigniter URL中的index.php

http://localhost/Sample/index.php 

只是

http://localhost/Sample

我一直在尋找整天在互聯網上,並沒有什麼作品。我使用的是Apache2.2,並且httpd.conf中的mod_rewrite已經啓用。我使用的版本是Codeigniter 2.1.4。

請教我一步一步來。我在Codeigniter Framework中仍然很新。謝謝 !

+0

我們需要看到您已經嘗試瞭解決方案。你能先給我們展示一些示例代碼嗎? –

回答

2

您可以使用下面的代碼在.htaccess文件:

RewriteEngine On 
RewriteBase /my_project_name/ 
# Do not enable rewriting for files or directories that exist 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
# Rewrite to index.php/URL 
RewriteRule ^(.*)$ index.php/$1 [PT,L] 
1

有兩個地方,你必須做出這種改變,一個是在你的/application/config/config.php

/* 
|-------------------------------------------------------------------------- 
| Index File 
|-------------------------------------------------------------------------- 
| 
| Typically this will be your index.php file, unless you've renamed it to 
| something else. If you are using mod_rewrite to remove the page set this 
| variable so that it is blank. 
| 
*/ 
$config['index_page'] = ''; 

刪除index.php來自索引頁面。

第二個地方是(如上所述)更新/創建您的.htaccess文件,該文件位於與您的主index.php文件相同的根文件夾中。

的Referer到CI指南:http://ellislab.com/codeigniter/user-guide/general/urls.html

這一切都在引導......

0

試試這個在根文件夾中找到您的.htaccess文件:

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond $1 !^(index\.php) 
RewriteRule ^(.*)$ index.php?/$1 [L,QSA] 
0
You just need to create .htaccess file in project folder and write: 

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> 

    #And You don't need to define in base_url in config file: 

     $config['base_url'] = '';// blank it. 

    I hope it will work perfectly ...