Flynn
Flynn

Reputation: 6181

Conditionally change URL using .htaccess

I'm learning about .htaccess, and have a file with the current rules:

Options -Indexes

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ /index.php [L]

Is there any way I can modify the RewriteCond to do only re-direct if the request does not end in .png or something else?

Upvotes: 1

Views: 86

Answers (2)

hwnd
hwnd

Reputation: 70722

Add another RewriteCond to exclude certain conditions that you don't want rewritten. As @acheong87 stated, prefix ! before the regular expression indicating that any files that match should fail.

RewriteCond %{REQUEST_URI} !\.(png|jpg|etc..)$

Upvotes: 3

Andrew Cheong
Andrew Cheong

Reputation: 30273

Prefix your expression with !, like so:

RewriteRule !\.png$ /index.php [L]

The $ is known as an anchor, and matches the end of the string.

Upvotes: 2

Related Questions