[英]Want to remove Index.php from Codigniter URL
我想從代碼點火器URL中刪除index.php ,我已經創建了.htaccess文件,並將其存儲在與index.php平行的應用程序文件夾中,還刪除了
$config['index_page'] = '';
來自config.php。
.htaccess文件中的代碼不起作用:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt)
RewriteRule ^(.*)$ /WCPM/index.php/$1 [L]
該項目的網址是:
localhost/WCPM/index.php
注意 : 請不要將此問題標記為重復,因為我已經嘗試過很多解決方案,但是沒有一個適合我,所以最后我在這里問這個問題的解決方案
在Config.php中,更改如下
$config['index_page'] = '';
$config['base_url'] = 'http://localhost/WCPM/';
並創建.htaccess文件,例如
RewriteEngine on
RewriteCond $1 !^(index\.php|[WCPM])
RewriteRule ^(.*)$ /WCPM/index.php/$1 [L]
並將其保存在根文件夾[WCPM]中,即在“應用程序文件夾”附近。
有關更多詳細信息,請參閱CI手冊@ http://ellislab.com/codeigniter/user-guide/general/urls.html
在apache中啟用mod_rewrite模塊。
如果不起作用或已經啟用了mod_rewrite,請嘗試此操作
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
首先,在config
文件中更改以下setting
。
$config['index_page'] = '';
然后,使用以下代碼替換位於項目根文件夾而不是應用程序文件夾中的.htaccess
文件。
RewriteEngine on
RewriteCond $1 !^(index\.php|public|\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|imgs)
RewriteRule ^(.*)$ index.php/$1 [L]
RewriteRule ^media/imatges/([0-9]+)/([A-Za-z0-9-]+).jpg?$ imgs/$1 [T=image/jpeg,L]
<Files "index.php">
AcceptPathInfo On
</Files>
這是放在.htaccess文件開頭的完整建議代碼。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.