I am new to url rewriting. My htaccess file has about 20 rewrites so far and more to come. I am curious if the more I have, will it slow my page load or anything of the sort?
我是url重写的新手。到目前为止,我的htaccess文件大约有20个重写文件。我很好奇,如果我有更多,它会减慢我的页面加载或任何类型的东西?
I am trying my best to structure my urls so I can have minimal rewrites but I am not sure if I have already failed by having 20 already.
我正在尽我所能来构建我的网址,以便我可以进行最小的重写,但我不确定我是否已经因为20已经失败了。
RewriteRule ^account/(\w+)(.*)$ ./index.php?option=account&task=$1 [L,PT]
# Auth Controller
RewriteRule ^auth/(\w+)(.*)$ ./index.php?option=auth&task=$1 [L,PT]
# Collections Controller
RewriteRule ^collections(.*)$ ./index.php?option=collections [L,PT]
RewriteRule ^collections/(\w+)(.*)$ ./index.php?option=collections&task=$1 [L,PT]
# Friends Controller
RewriteRule ^friends/(\w+)(.*)$ ./index.php?option=friends&task=$1&%{QUERY_STRING} [L,PT]
# Index Controller
RewriteRule ^index(.?)$ ./index.php?%{QUERY_STRING} [L,PT]
RewriteRule ^index/index(.?)$ ./index.php?%{QUERY_STRING} [L,PT]
RewriteRule ^about(.*)$ ./index.php?option=index&task=about [L,PT]
RewriteRule ^ideas(.*)$ ./index.php?option=index&task=ideas [L,PT]
RewriteRule ^contact(.*)$ ./index.php?option=index&task=contact [L,PT]
RewriteRule ^faq(.*)$ ./index.php?option=index&task=faq [L,PT]
# Messages Controller
#RewriteRule ^messages/(\d+)(.*)$ ./index.php?option=messages&account_id=$1 [L,PT]
# Run Controller
RewriteRule ^run/(\d+)(.*)$ ./index.php?option=run&account_id=$1 [L,PT]
# Stores Controller
RewriteRule ^stores/(\w+)(.?)$ ./index.php?option=stores&task=$1 [L,PT]
2 个解决方案
#1
4
Technically .htaccess
does slow down Apache but in reality the performance penalty is minuscule. Do not worry about having too many rewrites simply because of performance issues.
从技术上讲,.htaccess确实减慢了Apache的速度,但实际上性能损失是微不足道的。仅仅因为性能问题,不要担心重写太多。
Further reading: https://webmasters.stackexchange.com/questions/21055/alternative-to-htaccess-due-to-bad-performance
进一步阅读:https://webmasters.stackexchange.com/questions/21055/alternative-to-htaccess-due-to-bad-performance
But as Brad said, 20 rewrites sounds like a lot. I would condense them simply for readability purposes because it can get difficult to debug which rule does what when you have 20 rules on top of each other.
但布拉德说,20次重写听起来很多。我只是为了可读性目的而压缩它们,因为当你有20个规则在彼此之上时,调试哪个规则会变得很困难。
#2
0
Not really. If you have the ability to put them in the Apache configuration itself, they won't have to be reloaded with every request.
不是真的。如果您能够将它们放入Apache配置本身,则不必为每个请求重新加载它们。
#1
4
Technically .htaccess
does slow down Apache but in reality the performance penalty is minuscule. Do not worry about having too many rewrites simply because of performance issues.
从技术上讲,.htaccess确实减慢了Apache的速度,但实际上性能损失是微不足道的。仅仅因为性能问题,不要担心重写太多。
Further reading: https://webmasters.stackexchange.com/questions/21055/alternative-to-htaccess-due-to-bad-performance
进一步阅读:https://webmasters.stackexchange.com/questions/21055/alternative-to-htaccess-due-to-bad-performance
But as Brad said, 20 rewrites sounds like a lot. I would condense them simply for readability purposes because it can get difficult to debug which rule does what when you have 20 rules on top of each other.
但布拉德说,20次重写听起来很多。我只是为了可读性目的而压缩它们,因为当你有20个规则在彼此之上时,调试哪个规则会变得很困难。
#2
0
Not really. If you have the ability to put them in the Apache configuration itself, they won't have to be reloaded with every request.
不是真的。如果您能够将它们放入Apache配置本身,则不必为每个请求重新加载它们。