tags:

views:

12

answers:

2

Hello,

I am using CodeIgniter framework for PHP. It requires that index.php should be there in whatever url i type. How do i prevent this? Can anybody provide me a simple .htaccess file that will implicitly map it to index.php so user doesn't have to type it every time?

Thanks in advance:)

+1  A: 

You can use a .htaccess file (or better apache.conf) to forward all requests to index.php with mod_rewrite:

Options +FollowSymLinks
IndexIgnore */*

<ifmodule mod_rewrite.c> 
RewriteEngine on

    # if a directory or a file exists, use it directly
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

    # otherwise forward it to index.php
    RewriteRule . index.php
</ifmodule>

If your request is http://www.example.com/controller/view, than $_SERVER['REQUEST_URI'] is /controller/view. You can interpret it with Regex or by simply splitting string: explode('/',$_SERVER['REQUEST_URI']);

Sven Walter
+1  A: 

You need to read this http://codeigniter.com/wiki/mod_rewrite/ Because you'll also need to make a small code change (in step 2) not covered in Svens answer.

Wizzard
Thanks Wizzard, Can you tell me what does `$1` and `[L]` represent here ? ` RewriteRule ^(.*)$ /app/index.php/$1 [L]`
Ankit Rathod