views:

92

answers:

1

My current htaccess file looks like this:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteRule ^(.*)$ index.php?page=$1 [L,QSA]

This works fine for me, however I want to try and reduce server load so I have added this line just below the RewriteEngine On line to stop processing if loading static content:

RewriteCond %{REQUEST_FILENAME} !.*jpg$|.*gif$|.*png$|.*css$|.*js$|.*txt$|.*ico$|.*pdf$ [NC]

Is this the most efficient way of writing it? Thanks

+1  A: 

In line 2 you already check for existence of the requested file (!-f), so there is no need to add your line, but you could replace line 2 with your new rewrite condition, if you want to avoid returning other files like .php files. Performancewise I do not think this will speed up apache though, and there is some other performance hole in your web application.

That said, your pattern is probably not what you expected to be, as e.g. .*jpg$ matches mysuperjpg as well. You may be looking for \.jpg$, because . is a special character for regular expressions. You could do this:

RewriteCond %{REQUEST_FILENAME} !\.(jpg|gif|png|css|js|txt|ico|pdf)$ [NC]
Residuum