Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess 如何在codeigniter中删除URL末尾的index.php_.htaccess_Codeigniter - Fatal编程技术网

.htaccess 如何在codeigniter中删除URL末尾的index.php

.htaccess 如何在codeigniter中删除URL末尾的index.php,.htaccess,codeigniter,.htaccess,Codeigniter,我正在使用codeigniter框架。现在我想从URL中删除index.php 例如: www.domain.com/city/city name/index.php www.tomatosale.com/search/search field/index.php 实际上我想删除URL末尾的“index.php” 现在我的config.php$config['index']=' 请任何人帮助我如何做到这一点?在项目的根目录中添加一个htacess文件 RewriteEngine on # I

我正在使用codeigniter框架。现在我想从URL中删除index.php

例如:

  • www.domain.com/city/city name/index.php
  • www.tomatosale.com/search/search field/index.php
实际上我想删除URL末尾的“index.php”

现在我的config.php
$config['index']='


请任何人帮助我如何做到这一点?

在项目的根目录中添加一个htacess文件

RewriteEngine on
# If the request is not for a valid directory
RewriteCond %{REQUEST_FILENAME} !-d
# If the request is not for a valid file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond $1 !^(index\.php)
RewriteRule ^(.*)$ index.php/$1 [L]

我所有的CodeIgniter项目的根目录中都有这个

添加一个.htaccess文件

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    # Removes index.php from ExpressionEngine URLs
    RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
    RewriteCond %{REQUEST_URI} !/system/.* [NC]
    RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]

    # Directs all EE web requests through the site index file
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php/$1 [L]

重新启动发动机
重写基/
#从ExpressionEngine URL中删除index.php
RewriteCond%{THE_REQUEST}^GET.*index\.php[NC]
重写cond%{REQUEST_URI}/系统/*[NC]
重写规则(.*)索引\.php/*(.*)/$1$2[R=301,NE,L]
#通过站点索引文件指示所有EE web请求
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则^(.*)$/index.php/$1[L]


您可能还需要在Apache中启用
rewrite_模块
module

感谢您的回复,我已经尝试了这段代码,它只在www.domain.com/index.php上工作,现在我想在www.domain.com/city/city-name/index.php从url中删除index.php时工作正常吗?实际上我想删除url末尾的index.php。我将再次尝试这段代码,看看它是否有效。我去哪里启用这个“重写_模块”?这是在您的本地计算机上还是服务器上?您可以在终端上使用命令“a2enmod rewrite”?现在我使用的是godaddy服务器,应该可以使用godaddy-请参阅