-2

i have the same problem as many people to remove the index.php from url in codeigniter.

i always done all response from precedent answer, but i always can access to a url with index.php

this url work : https://www.domaine.tld/Test but i can access : https://www.domaine.tld/index.php/Test (work too)

i dont have any link in my site which include index.php but my question is about how redirect url with index.php to dont have duplicate content.

thanks for your answer.

  • http://www.htaccess-guide.com/ maybe htaccess will solve the problem for you. Just redirect "/" to "/index.php" – SparklyUnicorn Jan 08 '19 at 11:17
  • who knows of the existence of https://www.domaine.tld/index.php/Test except you? you write: "I don't have any link in my site which include index.php", the part "remove index.php from url" is answered extensively here: https://stackoverflow.com/questions/19183311/codeigniter-removing-index-php-from-url – Vickel Jan 09 '19 at 00:47

5 Answers5

0

Codeigniter have beautiful documentation.you can find all things related Codeigniter is in Codeigniter user_guide for now to solve your issue create .htaccess file in root and paste following code

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

And then also remove the index.php from

application/config/config.php

$config['index_page'] = 'index.php';

changes to

$config['index_page'] = '';

Learn more at: https://www.codeigniter.com/userguide3/general/urls.html

TarangP
  • 2,711
  • 5
  • 20
  • 41
0

Put this in your .htaccess :

RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA] 

Open config.php and do following replaces

$config['index_page'] = "index.php"

to

$config['index_page'] = ""
Gulmuhammad Akbari
  • 1,986
  • 2
  • 13
  • 28
0

Go to your config.php under application/config/config.php, you need to change two configs there, setting your base_url and deleting the index_page value:

$config['base_url'] = 'your_base_url';
$config['index_page'] = '';

Then in you FCPATH create a .htaccess file with the following content:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

Now everything should work just fine (unless you are using lamp cause in this case your need to do some extra steps in your apache configurations).

Sherif Salah
  • 2,085
  • 2
  • 9
  • 21
0

thanks for your response. i always do that, but not worked and i dont understand why.... i'm on apache2 / rewrite module enable

i modify the virtual host too AllowOverride All

    Options Indexes FollowSymLinks MultiViews

    DirectoryIndex index.html index.phtml index.php
    php_admin_flag engine On
     AddType application/x-httpd-php .php .phtml .php3
    </Directory>
0

This will be helpful on lamp


Put this code on your .htaccess file

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1

open

application/config/config.php

remove index.php

$config['index_page'] = "";

then set

$config['base_url'] = 'your site base_url';