oxygen
oxygen

Reputation: 6039

.htaccess mod rewrite regex to not match file names

I am using the following .htaccess configuration directives (to redirect all non filename requests to a single PHP file):

RewriteEngine on
Options +FollowSymLinks
RewriteBase /

RewriteRule !(\.ttf|\.eot|\.woff|\.xpi|\.xml|\.txt|\.air|\.exe|\.zip|\.pdf|\.ico|\.gif|\.jpg|\.png|\.jpeg|\.js|\.swf|\.css|\.php|\.html)$ mod_rewrite_redirector.php [L]

How can I make the above regex case insensitive? I have tried [L,NC] or placing (?i) at the beggining. NC option doesn't work on all Apache2 installations (various versions) and (?i) has no effect.

How can I make a regex which will not match URLS which look like a filename with an extension between 2 and 4 characters?

Thank you for your help.

Upvotes: 1

Views: 1495

Answers (1)

Oussama Jilal
Oussama Jilal

Reputation: 7739

Try this :

RewriteRule !\.[a-zA-Z0-9]{2,4}$ mod_rewrite_redirector.php [L]

But if you want to redirect requests to files that does not exists on your server, it is better to use :

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . mod_rewrite_redirector.php [L]

Upvotes: 1

Related Questions