开发者

600 + mode rewrite rules, is that okay with apache?

We are building a website that hopefully will serve 2k-5k uniques per day. Because the website is oriented for arab speakers we configured the .htaccess file to make rewrite rules like:

RewriteRule ^عربية$ arabic.php [L]

Problem is we have 600 Rewri开发者_运维知识库te Rules like the one above. Is this Okay with apache? or is this going to make my server real slow? does the [L] tag help?


If you have just static keywords, I would rather use a hash map instead of separate rules. Because the complexity of the find operation for a hash map is O(1) in opposite to O(n) for n rules.

So you could do something like this:

RewriteMap arabic-keywords dbm:/path/to/file/arabic-keywords.map

The initial keywords map is a plain text file of the format:

عربية arabic.php
الأغاني songs.php
الفنان artist.php

Then use httxt2dbm to turn the plain text file into a hash map:

httxt2dbm -i arabic-keywords.txt -o arabic-keywords.map

And the use of the map:

RewriteCond %{arabic-keywords:$0} .+
RewriteRule .+ %0 [L]

As a hash rewrite map returns an empty string if no match was found, the condition will only be fulfilled if a match was found. But note that RewriteMap cannot be used in the .htaccess file context.


I think this is too much for performance and for maintainability.

I would make one rewrite rule to forward everything related requests to arabic.php, then process the $_SERVER['REQUEST_URI'] with php for more dynamic routing.

This would be more maintainable.


I'm doing maintenance on a website with similar vistor rates and it has currently around 500 mod rewrite rules. They have little impact on the overal performance.

The [L] tag does help a bit in this performance. Especially if you keep your most used rules on the top of the page.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜