这个 .htaccess 是否存在确实会减慢页面请求速度的问题?

发布于 2024-09-27 11:23:41 字数 319 浏览 0 评论 0原文

自从将这个基本的 .htaccess 添加到我的索引目录后,每个页面加载速度可能会减慢 20-30 秒:

Options +FollowSymlinks
RewriteEngine on

RewriteRule ^(.+)-(.+) movie.php?id=$1 [NC]

这里是否存在一些格式错误或错误的正则表达式格式?我看不出有什么问题。

谢谢!

作为更新,仅这两行就足以减慢速度:

Options +FollowSymlinks
RewriteEngine on

Since adding this basic .htaccess to my index directory, each page load slows down by maybe 20-30 seconds:

Options +FollowSymlinks
RewriteEngine on

RewriteRule ^(.+)-(.+) movie.php?id=$1 [NC]

Is there some malformation or bad regex formatting here? I can't see anything wrong with it.

Thanks!

As an update, just these 2 lines are enough to put the slow down on:

Options +FollowSymlinks
RewriteEngine on

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

醉南桥 2024-10-04 11:23:41

看起来您正在通过电影脚本运行请求。那么 movie.php 脚本需要多长时间才能运行?如果需要 20-30 秒,那么就可以了!

It looks like you're running requests through your movie script. So how long does it take your movie.php script to run? If it takes 20-30 seconds, well, then there you go!

べ繥欢鉨o。 2024-10-04 11:23:41

尽管我认为 20-30 秒有点牵强,但这里对您当前的正则表达式有一些担忧:

  • 您的正则表达式的一部分不是必需的,所以放弃它。特别是如果这部分看起来已经有很多回溯((.+) 确实如此)。因此,您可以将正则表达式简化为 ^(.+)-
  • 您正在将 ID 与 (.+) 相匹配。这不是最佳方法。最好使用 ([^-]+) 代替。这将处理任何不是 - 的字符(这就是您想要的。)

因此生成的规则是:

RewriteRule ^([^-]+)- movie.php?id=$1 [NC]

更好(这仅允许整数 ID):

RewriteRule ^([0-9]+)- movie.php?id=$1 [NC]

Even though I think that 20-30 seconds is a little bit far-fetched, here some concerns about your current regex:

  • Part of your regex isn't required, so drop it. Especially if this part already looks like a lot of backtracking (and (.+) does). Thus you may reduce the regex to ^(.+)-.
  • You are matching an ID with (.+). That isn't the optimal approach. Better use ([^-]+) instead. This will mach any char that isn't an - (and that's what you want.)

The resulting Rule thus is:

RewriteRule ^([^-]+)- movie.php?id=$1 [NC]

Even better (this allows only integral IDs):

RewriteRule ^([0-9]+)- movie.php?id=$1 [NC]
︶葆Ⅱㄣ 2024-10-04 11:23:41

打开重写日志记录并提高级别,看看您的 RewriteRule 正在做什么:

http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewritelog
http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewriteloglevel

如果正则表达式必须超时工作,您很快就会看到 Apache 的错误日志大小呈爆炸式增长,尤其是在更高级别的重写日志记录中。

Turn on rewrite logging and crank the level up, see what your RewriteRule is doing:

http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewritelog
http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewriteloglevel

If the regex is having to work overtime, you'll quickly see Apache's error log explode in size, especially at the higher levels of rewrite logging.

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