我的 htaccess 中的 url 重写过多是件坏事吗?
我是 url 重写的新手。到目前为止,我的 htaccess 文件已经重写了大约 20 次,以后还会有更多重写。我很好奇我拥有的越多,是否会减慢我的页面加载速度或类似的情况?
我正在尽力构建我的网址,这样我就可以进行最少的重写,但我不确定我是否已经失败了 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]
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?
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.
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]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从技术上讲,
.htaccess
确实会降低 Apache 的速度,但实际上性能损失很小。不要仅仅因为性能问题而担心进行过多的重写。进一步阅读:https://webmasters.stackexchange.com/questions/21055 /alternative-to-htaccess-due-to-bad-performance
但正如 Brad 所说,20 次重写听起来很多。我只是出于可读性目的而将它们压缩,因为当您有 20 个规则相互叠加时,调试哪个规则执行什么操作可能会很困难。
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.Further reading: 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.
并不真地。如果您能够将它们放入 Apache 配置本身,则不必在每个请求时重新加载它们。
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.