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

时间:2017-02-02 11:53:46

标签: .htaccess codeigniter

我正在使用codeigniter框架。现在我想从URL

中删除index.php

示例:

  • www.domain.com/city/city-name/index.php
  • www.tomatosale.com/search/search-field/index.php

其实我想要删除" index.php"在URL的末尾,

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

请有人帮我怎么做?

2 个答案:

答案 0 :(得分:0)

在项目的根目录中添加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]

答案 1 :(得分:0)

我在所有CodeIgniter项目的root

中都有这个

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

您可能还需要在Apache

中启用rewrite_module模块