0

Possible Duplicate:
CodeIgniter - How to hide index.php from the URL

How can I remove index.php from the URL using .htaccess so when user types in, for example:

http://localhost/index.php/welcome

it will become :

http://localhost/welcome

Currently With my current .htaccess, both of the urls above will be able to access the controller welcome, but I would like only 1 valid url for the controller.

RewriteEngine on
RewriteCond $1 !^(index\.php|admin_assets|img|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1
Community
  • 1
  • 1
Zekiel
  • 1

3 Answers3

1

in your config.php file search for this line:

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

edit it like this:

$config['index_page'] = ""; //remove index.php from there

and add this in your htaccess:

Options +FollowSymLinks

Options -Indexes

DirectoryIndex index.php

RewriteEngine on



RewriteCond $1 !^(index\.php|resources|images|css|js|robots\.txt|favicon\.ico|sitemap\.xml)

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php?/$1 [L,QSA]

Hope this helps.

talha2k
  • 24,937
  • 4
  • 62
  • 81
  • this also does not works, Zekiel want to redirect: `http://localhost/index.php/welcome` to `http://localhost/welcome` he say that url rewrites works he just need to redirect – tttony Sep 05 '11 at 17:54
0

There are about 50000 questions handling this as well as a big wiki post about it

http://codeigniter.com/wiki/mod_rewrite/

ModRewrite not working for codeigniter site

Rewrite URLs in CodeIgniter

CodeIgniter - How to hide index.php from the URL

... those should help

Community
  • 1
  • 1
austinbv
  • 9,297
  • 6
  • 50
  • 82
  • 1
    Nope, these dont tell me how to actually remove the index.php from the URL when user typing in index.php/welcome. basically, all the articles and threads were about making http://localhost/welcome a valid request. – Zekiel Sep 05 '11 at 03:20
0

Simple and fast solution :

Just create a .htaccess file with the below code

RewriteEngine on
RewriteCond $1 !^(admin_assets|img|css|js|robots\.txt|favicon\.ico)
RewriteRule ^(.*)$ index.php/$1 [L]

And then place it to the root of your CI application near index.php.
This modified .htaccess file satisfy your requirements, (ie you don't want the user to be able to access the same page with 2 different urls's)

Q. What will it do?

A. It will guide all request to your application to index.php including those url which contains index.php except(admin_assets,img,css,js folder and your robots.txt, favicon.ico files) obviously on apache.

CodeIgniter's own documentation is very good, URL's in CI

Pawan Choudhary
  • 1,073
  • 1
  • 10
  • 20