[英]How to remove the index.php from url in codeigniter project
我正在Codeigniter創建一個網站。 這是我所知道的非常常見的問題,Stack Overflow上有很多解決方案。 我嘗試幾乎所有,但沒有什么對我有幫助。
我只是想從我的網址中刪除index.php。 有人請告訴我怎么辦?
我已經從配置文件的$config['index_page']
部分刪除了index.php
我還檢查了$config['uri_protocol'] = 'AUTO';
模式嘗試模式auto和REQUEST_URI
。
我的.httaccess文件結構現在是這樣的:
<IfModule authz_core_module>
Require all denied
</IfModule>
<IfModule !authz_core_module>
Deny from all
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>
有人可以告訴我怎么做嗎?
$config['uri_protocol']
應該是REQUEST_URI
,然后是.htaccess
,如下所示
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
我有以下內容,對我來說很好:
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|(.*)\.swf|forums|images|css|downloads|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php?$1 [L,QSA]
$config['index_page'] = ''; $config['uri_protocol'] = 'AUTO';
RewriteEngine on RewriteCond $1 !^(index\\.php|resources|robots\\.txt) RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L,QSA]
注意: .htaccess
因服務器而異。 在某些服務器(例如:Godaddy)需要使用以下.htaccess
:
RewriteEngine on RewriteCond $1 !^(index\\.php|resources|robots\\.txt) RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
嘗試這個 ...
RewriteEngine On
RewriteBase /music
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
重寫基礎/音樂是您的文件夾名稱
=>更改配置文件: -
$config['base_url'] = 'http://123456/proj/';
$config['index_page'] = '';
=>更改.htaccess文件: -
RewriteEngine on
RewriteCond $1 !^(index\.php|
(.*)\.swf|forums|images|css|downloads|jquery|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php?$1 [L,QSA]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.