繁体   English   中英

codeigniter 删除 index.php 表单 url

[英]codeigniter remove index.php form url

我正在尝试从 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]

上面的基本 url 程序。 所以我将在这个程序中改变它在子文件夹上工作。

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

 `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" `

采取与您在 example.com 文件夹中所做的完全相同的步骤,从 example.com/folder 文件夹的基本 url 中删除 index.php。 也就是说,编辑/创建 htaccess,从配置文件中删除 index.php 等。

将此代码写入您的 .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

它的工作..

快速解决方案

RewriteEngine On
RewriteCond %{HTTP} off
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

如果遇到问题

您可能需要检查您的apache是否安装并启用了modrewrite

启用改写

sudo a2enmod rewrite

还要确保

sudo vi /etc/apache2/apache2.conf

并允许符号链接

<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
</Directory>

重新启动apache2 ,您的.htaccess应该可以正常工作。

在此处输入图片说明

阅读最后一步: https : //www.intelligentcomp.com/2017/07/how-to-setup-and-configure-lamp-on-ubuntu-server.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM