簡體   English   中英

從codeigniter url中刪除index.php

[英]Remove index.php from codeigniter url

我是codeigniter的新手。 我在localhost / path / learn_ci上安裝了我的codeigniter。

我已經遵循了codeigniter wiki中給出的所有步驟。 這是我的.htaccess文件。

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /learn_ci/index.php/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>

我還根據需要更改了配置文件。 但是當我試圖訪問時

我收到這個錯誤

“在此服務器上找不到請求的URL /learn_ci/index.php/welcome”

我已經仔細檢查了...... Apache中的mod_rewrite模塊已啟用。

RewriteBase解決方案也不起作用。 難道我做錯了什么??

正如其他人所說,請確保在apache配置或虛擬主機文件中將AllowOverride設置為All。 鑒於您已設置codeigniter的路徑,您的htaccess應如下所示:

RewriteEngine On
RewriteBase /path/learn_ci

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /path/learn_ci/index.php/$1 [L]

此外,請記住您使用的任何資產(img,css,js等)都使用base_url()函數或使用相對路徑引用。 項目的根目錄是/ path / learn_ci。

我發現創建虛擬主機並在本地向主機文件添加條目更容易。 這樣可以更好地模仿現實生活。

嘗試:

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]  

您可以執行以下操作:

首先在config.php文件集中

$config['index_page'] = '';

接下來,在codeigniter根文件夾中創建.htaccess文件並添加以下內容:

RewriteEngine on
RewriteCond $1 !^(index\.php|public|\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1

保存文件。 它應該工作。

將htaccess文件放在root public_html文件夾中,與index.php位於同一目錄中

然后從你的htaccess文件中刪除/ learn_ci,只需將其設為/index.php/$1

檢查你的apache配置,它應該是這樣的:

Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all

我想加上我的回答。 我的項目基本URL是http://localhost/newproject/我在newproject文件夾中包含了htacess文件。

這是代碼。

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php/$1 [L,QSA]

然后我改變配置文件。

$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';

每件事都開始奏效了。 現在nomore index.php文件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM