首页 文章

codeigniter删除index.php表单url

提问于
浏览
2

我想在Codeigniter中从url中删除"index.php" . 我知道如何从基本URL中删除index.php,如 example.com/controller .

但我不知道如何删除子文件夹中的"index.php",如 example.com/folder/index.php/controller

因为我必须在codeigniter中使用不同的项目 . 所以我已经在子文件夹中上传了第二个项目 .

.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]

以上基本网址的程序 . 那么我将在这个程序中更改它在子文件夹上工作 .

4 回答

  • 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

    在config.php $config['index_page'] = ''; 中更新此变量 . 删除 index.php

  • 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的默认设置无法正常工作 . 要解决此问题,只需打开位于application / config中的文件config.php,然后查找并替换代码:

    //找到下面的代码

    $config['uri_protocol'] = "AUTO"
    

    //替换为

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

    执行与example.com文件夹完全相同的步骤,从example.com/folder文件夹的基本URL中删除index.php . 也就是说,编辑/创建htaccess,从配置文件中删除index.php等 .

相关问题