开发者

How do i map myapp/index.php/controller/view to myapp/controller/view?

开发者 https://www.devze.com 2023-01-07 08:04 出处:网络
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

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']);

0

精彩评论

暂无评论...
验证码 换一张
取 消