开发者

Rewrite rule with the exception of static content

My 开发者_StackOverflow中文版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


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]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜