600 +模式重写规则,apache可以吗?
我们正在建立一个网站,希望每天能够为 2,000 到 5,000 名独立用户提供服务。 因为该网站是面向阿拉伯语使用者的,所以我们配置了 .htaccess 文件来制定重写规则,例如:
RewriteRule ^عربية$ arabic.php [L]
问题是我们有 600 个像上面这样的重写规则。 apache 可以吗?或者这会让我的服务器变得非常慢? [L] 标签有帮助吗?
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 Rewrite 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您只有静态关键字,我宁愿使用 哈希映射 而不是单独的规则。因为哈希映射的查找操作的复杂度为 O(1),而 n 规则的查找操作复杂度为 O(n)。
因此,您可以执行以下操作:
初始关键字映射是格式为的纯文本文件:
然后使用
httxt2dbm
将纯文本文件转换为哈希映射:以及映射的使用:
作为哈希重写映射,如果未找到匹配项,则返回空字符串,仅当找到匹配项时才会满足条件。但请注意,
RewriteMap
不能在 .htaccess 文件中使用 上下文。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:
The initial keywords map is a plain text file of the format:
Then use
httxt2dbm
to turn the plain text file into a hash map:And the use of the map:
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.我认为这对于性能和可维护性来说太多了。
我会制定一项重写规则,将所有相关请求转发到 arabic.php,然后使用 php 处理 $_SERVER['REQUEST_URI'] 以实现更动态的路由。
这会更易于维护。
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.
我正在维护一个访问率相似的网站,目前它有大约 500 个 mod 重写规则。它们对整体性能影响不大。
[L]
标签确实对性能有所帮助。特别是如果您将最常用的规则保留在页面顶部。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.