2013-01-04 135 views
-3

我是CodeIgniter的新手。我在Windows 8上有一個XAMPP服務器。一切都很好,但問題是關於我的URL,它看起來不友好。它看起來像localhost/ci/index.php/site/home(其中ci是我的CodeIgniter的根文件夾)。我想讓URL更乾淨,比如localhost/ci/home,我該怎麼做?如何從CodeIgniter的URL中刪除index.php?

我的CodeIgniter版本是2.1.2。

我已經做了一些研究,但在大多數情況下,它說要更改CodeIgniter的.htaccess文件。但我在.htaccess文件中沒有任何內容;它是空的,除了「拒絕所有」這一行。

+0

我不理解你的問題。你認爲你的'.htaccess'文件應該保持爲空,儘管這些文檔正好告訴你放在那裏。解決方案:將其從RTM中取出並按照說明操作。 – Sparky

+0

可能重複的[在codeigniter 2.1.0中刪除index.php](http://stackoverflow.com/questions/9667226/remove-index-php-in-codeigniter-2-1-0) – Sparky

回答

1

你可以做到這一點,在config/config.php

$config['base_url'] = 'http://'.$_SERVER['HTTP_HOST']; //you can also leave blank this CI tend to find this by himself 
$config['index_page'] = ''; 

,試試下列.htaccess。我用它爲許多網站,它滿足我。

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

如果沒有工作,使用phpinfo();並檢查是否mod_rewrite的是enabled。如果未啓用,則可以按照堆棧溢出問題How do you enable mod_rewrite?中的說明啓用該功能。

如果沒有工作,mod_rewrite的是enabled然而,你可以嘗試在config/config.php切換這些:

$config['uri_protocol'] = 'AUTO'; //If not working, try one of these: 
    'PATH_INFO'  Uses the PATH_INFO 
    | 'QUERY_STRING' Uses the QUERY_STRING 
    | 'REQUEST_URI'  Uses the REQUEST_URI 
    | 'ORIG_PATH_INFO' Uses the ORIG_PATH_INFO 
0

看着官方文檔,CodeIgniter URLs

你可以通過使用帶有一些簡單規則的.htaccess文件輕鬆刪除此文件。這裏有這樣一個文件的例子,使用中,一切都被重定向,除了指定項目的「消極」的方法:

RewriteEngine on<br> 
RewriteCond $1 !^(index\.php|images|robots\.txt)<br> 
RewriteRule ^(.*)$ /index.php/$1 [L]<br> 

此外,如果你使用的是Apache的地方.htaccess文件在你的根Web目錄。欲瞭解更多信息,請看Codeigniter .htaccess