Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.htaccess allow image to display directly

I have many files including images, php& js scripts and subfolders. I need to redirect to index.php for any uri using .htaccess.
for example:

www.example.com/test should be redirect to index.php

But images should not be redirected to index.php. Instead it should be printed directly in browser.
For example:

www.example.com/sample.jpg should display sample.jpg.

I am using following codes in .htaccess code:

RewriteEngine On  
RewriteRule ^(.*)$ index.php

Can someone explain how to allow image to display?

like image 776
Ijas Ahamed N Avatar asked Jun 16 '15 13:06

Ijas Ahamed N


1 Answers

Add conditions before your rule to skip image/css/js filesdirectories:

RewriteEngine On

RewriteRule !\.(?:jpe?g|gif|bmp|png|tiff|css|js)$ index.php [L,NC]
like image 72
anubhava Avatar answered Oct 07 '22 14:10

anubhava