[英]Removing index.php from url [Codeigniter]
首先,請原諒我提出這個問題,因為已經討論了很多次了。 我嘗試了遇到的所有問題,但我覺得自己做錯了什么。 因此,在這種情況下,我將提供一些幫助。
我想從網址中刪除“ index.php”。 目前的網址是
http://localhost/eshop/index.php/home
但是我想要
http://localhost/eshop/home
這是我的.htaccess
RewriteEngine on
RewriteCond $1 !^\/(index\.php|res|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
我也嘗試過
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /eshop/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
這樣,只有“ http://localhost/eshop/
”有效,但“ http://localhost/eshop/home
”或“ http://localhost/eshop/contacts
”仍然失敗。
另外,您應該對CI表示未將index.php插入生成的網址
https://ellislab.com/codeigniter/user-guide/general/urls.html
您還需要更改配置
$config['enable_query_strings'] = FALSE;
有幾種變體(例如將索引頁設置為空字符串-請參閱本主題CodeIgniter從url中刪除index.php )
在項目的根文件夾中創建一個.htaccess文件,然后粘貼此代碼
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
並在config.php中
$config['base_url'] = '';
以下.htaccess應該有效。
RewriteEngine on
RewriteCond $1 !^(index.php|resources|robots.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.