2010-07-17 118 views

回答

1

你需要閱讀本 http://codeigniter.com/wiki/mod_rewrite/ 因爲你還需要進行一個小的代碼更改(步驟2)不包括在Svens答案。

+0

謝謝Wizzard,你能告訴我'$ 1'和'[L]'代表什麼嗎? 'RewriteRule ^(。*)$ /app/index.php/$1 [L]' – TCM 2010-07-17 02:52:24

1

您可以使用.htaccess文件(或更好的apache.conf)轉發所有請求與mod_rewrite的到index.php:

Options +FollowSymLinks 
IndexIgnore */* 

<ifmodule mod_rewrite.c> 
RewriteEngine on 

    # if a directory or a file exists, use it directly 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 

    # otherwise forward it to index.php 
    RewriteRule . index.php 
</ifmodule> 

如果您的請求是http://www.example.com/controller/view ,而不是$ _SERVER ['REQUEST_URI']是/ controller/view。您可以使用正則表達式或簡單地分割字符串來解釋它:explode('/',$ _ SERVER ['REQUEST_URI']);