在我的htaccess中有太多的url重写是一件坏事吗?

Jus*_*son 8 php .htaccess mod-rewrite

我是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]
Run Code Online (Sandbox Code Playgroud)

The*_*eLQ 4

从技术上讲,确实.htaccess会减慢 Apache 的速度,但实际上,性能损失很小。不要仅仅因为性能问题而担心进行过多的重写。

进一步阅读:https://webmasters.stackexchange.com/questions/21055/alternative-to-htaccess-due-to-bad-performance

但正如 Brad 所说,20 次重写听起来很多。我只是出于可读性目的而将它们压缩,因为当您有 20 个规则相互叠加时,调试哪个规则执行什么操作可能会很困难。