2016-09-22 133 views
2

我想從Codeigniter中的url中刪除「index.php」。我知道如何從基礎網址中刪除index.php,例如example.com/controllercodeigniter刪除index.php表單url

但我不知道如何刪除「的index.php」子文件夾一樣example.com/folder/index.php/controller

,因爲我已經在笨不同的項目。所以第二個項目我已經上傳到子文件夾中。

的.htaccess

#original 
#RewriteEngine on 
#RewriteCond $1 !^(index\.php|images|robots\.txt) 
#RewriteRule ^(.*)$ index.php/$1 [L] 

#modify 
RewriteEngine on 

RewriteCond $1 !^(index\.php|resources|robots\.txt) 

RewriteCond %{REQUEST_FILENAME} !-f 

RewriteCond %{REQUEST_FILENAME} !-d 

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

RewriteBase/
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] 
RewriteRule ^(.*)$ http://%1/$1 [R=301,L] 

爲基本URL上述程序。所以我將在這個程序中改變它在子文件夾上的工作。

回答

0

寫這樣的代碼在.htaccess文件

# BEGIN WordPress 
<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase/
RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /folder/index.php [L] 
</IfModule> 

# END WordPress 

例子:example.com/folder/index.php/ contorller

上面的代碼後,沒有必要寫的index.php

它的工作..

+0

謝謝...它的工作 – joy

+0

你的歡迎.... – Gagan

0

在config.php $config['index_page'] = '';中更新這個變量。刪除index.php

+0

僅憑這一點就不會從你的URL中刪除index.php文件,則需要使用某種形式的mod_rewrite如一個ht訪問文件以正確刪除它。 – killstreet

0
`Step:-1 Open the file config.php located in application/config path. Find and Replace the below code in config.php file. 

//查找下面的代碼

$config['index_page'] = "index.php" 

//刪除的index.php

$config['index_page'] = "" 

步驟:-2轉到您的CodeIgniter文件夾並創建.htaccess文件。

路徑:

Your_website_folder/ 
    application/ 
    assets/ 
    system/ 
    user_guide/ 
    .htaccess <--------- this file 
    index.php 
    license.txt 

步驟:-3下面寫下代碼在.htaccess文件

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

步驟:-4在某些情況下,uri_protocol默認設置不起作用正常。爲了解決這個問題,只需打開位於應用程序/配置文件config.php文件,然後找到並更換代碼:

//查找下面的代碼

$config['uri_protocol'] = "AUTO" 

//取代它成爲

$config['uri_protocol'] = "REQUEST_URI" ` 
+0

先生,,你的邏輯不工作.. – joy

0

採取與您在example.com上完成的文件夾完全相同的步驟,從example.com/folder文件夾的基礎URL中刪除index.php。也就是說,編輯/創建htaccess的,除去配置文件的index.php等