[英]unable to remove index.php from codeigniter url in live site
我需要從我的 codeigniter url 中刪除 index.php。 這是我在 .htaccess 文件中的代碼:
RewriteEngine On
RewriteRule ^index.php/(.*)$ /$1 [R=302,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ index.php?/$1 [L]
和 config.php 文件中的修改:
$config['base_url'] = 'http://example.com/'
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
在我的本地主機上工作正常。 但在我的實時站點中,它會生成 404 錯誤。
我可以使用 index.php (' http://example.com/index.php/Home ') 加載 url,但是 ' http://example.com/Home ' 會產生 404 錯誤。 為什么這只發生在現場? 是否需要其他更改? 還有一件事,它不是 apache 服務器,我的網站是在 iis 中發布的
將以下代碼粘貼到您的 .htaccess 文件中
RewriteEngine On
#RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php/$1
然后轉到 config 文件夾中的配置文件並從中刪除 index.php
$config['index_page'] = '';
如果您的站點位於子文件夾中,則必須在“#RewriteBase /”之后添加子文件夾名稱
我想你不見了
重寫基數 /
這是完整的 htaccess,它應該位於主項目文件夾中。 如果它在子文件夾中,您必須編寫 rewritebase。
<IfModule mod_rewrite.c>
RewriteEngine On
# !IMPORTANT! Set your RewriteBase here and don't forget trailing and leading
# slashes.
# If your page resides at
# http://www.example.com/mypage/test1
# then use
# RewriteBase /mypage/test1/
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
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.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.