2016-09-22 132 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等