Ijas Ahamed N
Ijas Ahamed N

Reputation: 6110

.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?

Upvotes: 6

Views: 4126

Answers (1)

anubhava
anubhava

Reputation: 785661

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]

Upvotes: 5

Related Questions