Is it okay to have a very long .htaccess file?

前端 未结 5 1561
悲&欢浪女
悲&欢浪女 2020-12-16 02:05

I am giving out URLs to people on a website, that actually point to something ugly (on the same website).

http://www.mydomain.com/cool-URL
actually points to

5条回答
  •  鱼传尺愫
    2020-12-16 02:45

    Having that much rules is really inadvisable. It’s not that they are in a .htaccess file or that they are tested for each request. (Depending on the configuration, that’s might also happen if you put them into your server’s or virtual host configuration.)

    It’s the mere fact that it’s that huge amount of rules that is tested and, depending on the rules, every rule has to be tested until a match is found.

    Well, you could counteract that by arranging the rules in the order of matching probability so that the probability of finding a match early is high. But it’s complexity is still O(n) in the worst case.

    If you really need that much mappings and the mappings are fixed, you can use a RewriteMap hash file that has a complexity of O(1) instead of O(n) for the separated rules. Or you shift the mapping to your PHP application and do it there.

提交回复
热议问题