600 +模式重写规则,apache可以吗?

发布于 2024-10-22 19:40:58 字数 232 浏览 1 评论 0原文

我们正在建立一个网站,希望每天能够为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

美人如玉 2024-10-29 19:40:58

如果您只有静态关键字,我宁愿使用 哈希映射 而不是单独的规则。因为哈希映射的查找操作的复杂度为 O(1),而 n 规则的查找操作复杂度为 O(n)。

因此,您可以执行以下操作:

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

初始关键字映射是格式为的纯文本文件:

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

然后使用 httxt2dbm 将纯文本文件转换为哈希映射:

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

以及映射的使用:

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

作为哈希重写映射,如果未找到匹配项,则返回空字符串,仅当找到匹配项时才会满足条件。但请注意,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:

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.

活泼老夫 2024-10-29 19:40:58

我认为这对于性能和可维护性来说太多了。

我会制定一项重写规则,将所有相关请求转发到 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.

別甾虛僞 2024-10-29 19:40:58

我正在维护一个访问率相似的网站,目前它有大约 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文