我是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个规则在彼此之上时,调试哪个规则会变得很困难.