[英]I can't remove the index.php from the CodeIgniter URL
我想從CodeIgniter中的路徑中刪除index.php。
我試圖在配置文件中更改index_page的值,如下所示:
$config['index_page'] = '';
然后我嘗試了所有這些.htaccess:
RewriteEngine on
RewriteBase /
# Hide the application and system directories by redirecting the request to index.php
RewriteRule ^(application|system|\.svn) index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
Options -Indexes
RewriteEngine on
RewriteCond $1 !^(index\.php|assets/|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
RewriteEngine on
RewriteCond $1 !^(index\.php|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
<Files "index.php">
AcceptPathInfo On
</Files>
但它們都沒有奏效。
我還試圖將uri_protocol更改為:
$config['uri_protocol'] = 'ORIG_PATH_INFO';
但它仍然無效。
我怎么解決這個問題 ?
我嘗試使用此代碼來檢查mod_rewrite是否已啟用:
<?php
if( ! function_exists('apache_get_modules') ){ phpinfo(); die; }
$result = ' not available';
if(in_array('mod_rewrite',apache_get_modules())) $result = 'available';
?>
<p><?php echo apache_get_version(),"</p><p>mod_rewrite $result"; ?></p>
我得到了這個結果:
Apache / 2.2.22(Ubuntu)
mod_rewrite不可用
我有同樣的問題..然后最終它使用以下代碼
只需按照以下簡單步驟:
1.將以下代碼保存到.htaccss文件中..
2.把它放在主項目文件夾(不是應用程序文件夾)中
3.將代碼第3行的“/ projectFolderName /”部分重命名為項目文件夾名稱。
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /projectFolderName/
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
這適合我。 Inyour .htaccess文件寫道:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
並在您的config.php文件中:
$config['uri_protocol'] = 'AUTO';
確保你的根文件夾中的htaccess不在應用程序文件夾中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.