[英]How do I remove 'index.php' from URL in CodeIgniter?
在.htaccess文件中試試這個:評論應該有助於為你調整它...
這在幾個CodeIgniter網站安裝中對我來說非常有效。 此外,如果未安裝mod_rewrite,它將發送到404頁面(或者您可以更改它以適應您的目的)。
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ index.php/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#This last condition enables access to the images and css folders, and the robots.txt file
RewriteCond $1 !^(index\.php|(.*)\.swf|images|robots\.txt|css|docs|cache)
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
ErrorDocument 404 /application/errors/404.php
</IfModule>
檢查虛擬主機文件,看看是否設置了這些項 - 這些可能允許.htaccess文件正確重寫URL :
Options FollowSymLinks
AllowOverride All
Order deny,allow
Deny from all
這100%有效,我試過了。 在.htaccess文件中僅添加以下內容:
RewriteEngine On
RewriteCond $1 !^(index\.php|(.*)\.swf|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
我也遇到了CodeIgniter用戶指南中建議的重寫規則的問題。 我通過從index.php前面刪除斜杠來解決它
RewriteRule ^(.*)$ index.php/$1 [L]
.htacess
RewriteEngine on
#Any HTTP request other than those for index.php,
#assets folder, files folder and robots.txt
#is treated as a request for your index.php file.
RewriteCond $1 !^(index\.php|assets|files|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
在此之后轉到application/config/config.php
並使用下面提到的值修改這兩個變量。
$config['base_url'] = '';
和
$config['index_page'] = '';
對於我的所有Codeigniter項目,我使用下面的.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.