[英]How to Remove index.php in URL
我嘗試刪除 Codeigniter 中的索引頁
我這樣做的第一步//舊代碼
$config['index_page'] = "index.php”
//新更新的代碼(只需要刪除 index.php )
$config['index_page'] = ""
然后第二步,我在 codigniter 的根目錄中創建文件 .htaccess,然后將此代碼源
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
但這是同樣的問題,我無法刷新網頁
有索引頁的 URL 工作: http://localhost:8089/codeigniter3/index.php/Hello/dispdata但沒有索引頁不工作http://localhost:8089/codeigniter3/Hello/dispdata
您好是控制器,最后感謝您的幫助,:)
問題是,你把它安裝在/codeigniter3/
這應該修復它:
// remove index.php
$config['index_page'] = ""
// Allow installation in a subfolder of your webroot
$config['uri_protocol'] = "REQUEST_URI"
並保留您的重寫設置,它們沒問題。
Codeigniter url 路由應該可以幫到你。 參考: https ://codeigniter.com/user_guide/general/routing.html
在名為 (.htaccess) 的主文件夾中創建一個新文件,並將此代碼粘貼到 .htaccess 文件中。
<IfModule mod_rewrite.c> RewriteEngine On RewriteBase /Enter your folder name/
刪除用戶對系統文件夾的訪問權限。 此外,這將允許您創建一個 System.php 控制器,以前這是不可能的。 如果您重命名了系統文件夾,則可以更換系統。
RewriteCond %{REQUEST_URI} ^system.* RewriteRule ^(.*)$ /index.php?/$1 [L]
當您的應用程序文件夾不在系統文件夾中時此代碼段會阻止用戶訪問應用程序文件夾
將“應用程序”重命名為您的應用程序文件夾名稱。
RewriteCond %{REQUEST_URI} ^application.* RewriteRule ^(.*)$ /index.php?/$1 [L]
檢查到
Rewrite Cond %{ENV:REDIRECT_STATUS} ^$
Rewrite Cond %{REQUEST_FILENAME} !-f
Rewrite Cond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
錯誤文檔 404 /index.php
試試這個
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
QSA
意味着如果有一個查詢字符串與原始 URL 一起傳遞,它將被附加到重寫
然后這樣做
//remove index.php
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
您可以在根文件夾的.htaccess
文件中嘗試以下代碼嗎
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
請遵循以下流程:
.htaccess
文件檢查服務器上是否啟用了mod_rewrite ?
RewriteEngine On RewriteCond %{REQUEST_FILENAME}.-f RewriteCond %{REQUEST_FILENAME}.-d RewriteRule ^(.*)$ index.php/$1 [L]`
這將解決您的問題。 如果您仍然面臨問題,請告訴我。
試試這個步驟:
$config['index_page'] = "index.php"
中刪除 index.php 在項目根文件夾中創建.htaccess
,如下代碼
RewriteEngine on RewriteBase /codeigniter3/ RewriteCond $1.^(index\.php|css|fonts|images|js) RewriteRule ^(.*)$ index?php?/$1 [L]
然后嘗試http://localhost:8089/codeigniter3/Hello/dispdata
我希望它能解決你的問題!
RewriteRule ^(.*)$ index.php/$1 [L]
由於您在.htaccess
指令中將正確的 URL 路徑作為附加路徑名信息(path_info) 傳遞,因此請嘗試在配置中顯式設置它:
$config['uri_protocol'] = 'path_info';
除非明確設置,否則它將嘗試各種方法,這些方法可能會失敗,因為您現在已經從 URL 中刪除了index.php
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.