php – 在我的htaccess中有太多的url重写是一件坏事吗?
发布时间:2020-12-13 13:27:39 所属栏目:PHP教程 来源:网络整理
导读:我是url重写的新手.到目前为止,我的htaccess文件大约有20个重写文件.我很好奇,如果我有更多,它会减慢我的页面加载或任何类型的东西? 我正在尽我所能来构建我的网址,以便我可以进行最小的重写,但我不确定我是否已经失败了已经有20个. RewriteRule ^account/(
我是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]
从技术上讲,.htaccess确实减慢了Apache的速度,但实际上性能损失是微不足道的.仅仅因为性能问题,不要担心重写太多.
进一步阅读:https://webmasters.stackexchange.com/questions/21055/alternative-to-htaccess-due-to-bad-performance 但布拉德说,20次重写听起来很多.我只是为了可读性目的而压缩它们,因为当你有20个规则在彼此之上时,调试哪个规则会变得很困难. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |