CodeIgniter: removing 'index.php' from URL

4.1k views Asked by At

I have answered this question previously and even posted the answer to it by myself. I tried most of the answered questions, but it still didn't work. The first question is regarding placement of the .htaccess file, should I keep it with application folder or inside it? and the next question is 'How should I remove the index.php from URL'?

.htaccess code:

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

Config.php code:

$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';

and if possible do also suggest a detailed tutorial regarding how to customize TankAuth or any other authentication library which can be easier. I am using Windows 8.1 and Wamp Server.

Any suggestion or help is appreciated.

7

There are 7 answers

2
sonam gupta On BEST ANSWER

Use this in your .htaccess file:

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

place ./ before your index.php rewrite rule.

or this

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]


For more detail refer link:https://ellislab.com/expressionengine/user-guide/urls/remove_index.php.html

0
Anshar Firman On

i think it will help you,

.htaccess

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

in config.php

    $http = 'http'.((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 's' : '').'://';
    $newurl = str_replace('index.php', '', $_SERVER['SCRIPT_NAME']);
    $config['base_url'] = "$http".$_SERVER['SERVER_NAME'].''.$newurl;
    $config['modules_locations'] = array('http://localhost/astrido_admin/application/' . 'modules/');

$config['index_page'] = '';

Thanks

1
Abdulla Nilam On

in config.php change this

$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';

and in .htaccess(NOTE: this should be place outside application folder)

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

Note: There are lot of duplicate question. So before Ask New Question please check your dropdown menu(its comes with when you start typing title of your question) whether its exist or answer provided.

0
AudioBubble On

Try this htaccess works fine windows 7 and 8.1 and xampp

Make sure you place the .htaccess in main directory and not the application folder.

Options +FollowSymLinks
Options -Indexes

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

Config

$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';

More htaccess https://github.com/riwakawebsitedesigns/htaccess_for_codeigniter

0
KBK On

enter image description here

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

application > config > config.php

$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';

definitely it will work.

0
adikur On

it works on me, I use v2.2.6 by the way

  • Create .htacccess on the same dir as your index.php
  • Modify index_page and base_url value in /application/config/config.php

here is what it looks like

picture image link

0
shafi On

1.config.php

$config['index_page'] = 'index.php';     change  to     $config['index_page'] = '’;

2.Create .htaccess file

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