0

I am using codeigniter framework. Now I want to remove index.php from URL

Example:

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

Actually I want to remove the "index.php" at end of the URL,

Now my config.php $config['index'] = '';

Please anyone help me how to do that?

greatwolf
  • 20,287
  • 13
  • 71
  • 105

2 Answers2

0

Add a htacess file in the root of your project

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]
Vimal
  • 1,140
  • 1
  • 12
  • 26
  • thank for your response, I had try this code, this working only www.domain.com/index.php, Now I want to www.domain.com/city/city-name/index.php – Sornaraj A Feb 02 '17 at 12:01
  • is it working when you remove the index.php from the url? – Vimal Feb 02 '17 at 12:03
  • Actually I want to remove index.php at end of the URL. Again I will try this code, Let see it is work or not – Sornaraj A Feb 02 '17 at 12:05
0

I have this in all of my CodeIgniter projects' root

Add a .htaccess file

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

You may also need the rewrite_module module enabled in Apache

Pooshonk
  • 1,284
  • 2
  • 22
  • 49