Вопрос

I have a quite simple question: Is the Apache RewriteRule time cost dependent on request content? Or is it constant, whatever the request size (content) is?

I need a very fast management of requests for a cloud based application, and some of my rewrite rules are "nice to have", like redirecting HTTP to HTTPS (I could simply returns 404 on HTTP instead). I suppose a rewrite rule costs about few milliseconds, but is it still true if I upload a very large file? Maybe Apache dumps the request content locally before rewriting and forwarding the request, which could cost a lot...

Thanks for your answers!

Это было полезно?

Решение

If apache is processing a rewrite rule size of content has no impact on it. For e.g. if you upload a 50 mb size file, file itself will not be processed by the rewrite rule. It's only the url or parts of it.

But what is important is how efficient your rewrite rules are.

By efficient I mean

1. what is regular expression that you use. Not all regular expressions will perform equal. After all they also process some string matching logic. if you can get same result with a simpler expression that will be fast.

2. How many rewrite rules are checked before a certain rule is applied and can you reduce those number of rules evaluated. You can find this by turning on the logging for mod_rewite. Based on this you can improve the rules. Remember "L flag" is your friend. See apache docs for how to use.

3. Well planned rewrite rules will also result in fewer rules and thus less costly to process.

Another thing that will play a part in this is size of urls. But that may not be in your control.

I hope it helps :)

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top