CI框架去掉index.php以及解決No input file specified問題
阿新 • • 發佈:2018-12-21
以下問題都容易解決,在此簡述
1,開啟apache的httpd.conf,開啟rewrite_module,並且將AllowOverride None改為AllowOverride None。
2,在專案中,和index.php以及system資料夾同級的目錄中,新建.htaccess檔案,並寫入一下程式碼
<IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L] </IfModule>
這時,如果在瀏覽器訪問首頁,比如專案名為citest,當輸入的url為
http://localhost/citest/Index/index時,會出現
No input file specified.
此時,只要將上述程式碼第四行中的
RewriteRule ^(.*)$ index.php/$1 [L]
修改為
RewriteRule ^(.*)$ index.php?/$1 [L]
即可,即在index.php與/之間新增一個?,這樣就能夠正常訪問了。
不過在使用輔助函式site_url()和base_url()時,兩個還是不太一樣,
使用site_url時的路徑為 http://localhost/citest/index.php
使用base_rul時的路徑為 http://localhost/citest/
如果要去掉site_url中的路徑,則在config.php中,將
$config['index_page'] = 'index.php';
修改為
$config['index_page'] = '';
即可
這樣無論是site_url還是base_url的路徑都為http://localhost/citest/