Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codeigniter's URL Rewriting

I'm using the following htaccess script so that I can hide index.php from the URI.

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

But I'm facing a major problem :(

I have a directory named assets beside my index.php file and it should be there. When I browse the directory by browser, then Codeigniter’s not found page displays. I can't browse the file /assets/image.jpg but it displays when I call it from an <img> tag

What can I do now?

Note that it is working in my local server (localhost) but not in the live server.

like image 599
A.N.M. Saiful Islam Avatar asked Jun 08 '10 04:06

A.N.M. Saiful Islam


1 Answers

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*)$ /index.php/$1 [NC,L]

That'll pass any request that Apache wouldn't serve off to CodeIgniter. This way you're free to create directories all over without updating your rewrite rules, and you don't need to setup 404 handling in Apache (even inside your image/resource directories).

Credit goes to the Zend Framework authors that recommend this bit in their user guide. This version is slightly modified for CodeIgniter.

like image 59
coreyward Avatar answered Oct 02 '22 20:10

coreyward