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:)
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.
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']);
精彩评论