Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在我的htaccess中重写过多url是件坏事吗?_Php_.htaccess_Mod Rewrite - Fatal编程技术网

Php 在我的htaccess中重写过多url是件坏事吗?

Php 在我的htaccess中重写过多url是件坏事吗?,php,.htaccess,mod-rewrite,Php,.htaccess,Mod Rewrite,我是新的url重写。到目前为止,我的htaccess文件已经重写了大约20次,以后还会有更多的重写。我很好奇,如果我拥有的越多,它是否会减缓我的页面加载或诸如此类的事情 我正在尽我最大的努力来组织我的URL,这样我可以有最小的重写,但我不确定我是否已经失败了,因为我已经有20个了 RewriteRule ^account/(\w+)(.*)$ ./index.php?option=account&task=$1 [L,PT] # Auth Controller RewriteRule

我是新的url重写。到目前为止,我的htaccess文件已经重写了大约20次,以后还会有更多的重写。我很好奇,如果我拥有的越多,它是否会减缓我的页面加载或诸如此类的事情

我正在尽我最大的努力来组织我的URL,这样我可以有最小的重写,但我不确定我是否已经失败了,因为我已经有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的速度,但实际上性能损失很小。不要仅仅因为性能问题就担心重写太多

进一步阅读:


但正如布拉德所说,20次重写听起来太多了。为了便于阅读,我会简单地对它们进行压缩,因为如果有20条规则相互叠加,则很难调试哪个规则起作用

不太可能。如果您能够将它们放在Apache配置中,那么就不必在每次请求时都重新加载它们。

为什么有20个?我还没有看到需要2或3个以上的配置。给我们看看你有什么。@Brad:如果你还没有看到那个配置,那并不意味着它毫无意义。在我们的大项目中,我们有几十条规则(最多一百条或更多)。我确信有更好的方法我不知道。到目前为止只有14个,但我还有更多。我认为我的主要问题是查询字符串的使用。什么时候它们应该成为新URL的一部分,或者只是作为查询字符串下注?这是个好问题,不过我不得不猜测Apache执行重写规则的速度要比您的情况下的替代方法快=have PHP gather(更多)复杂的参数并决定在何处传递控制。@贾斯汀·卡尔森:查询字符串怎么了?你不喜欢
%{QUERY\u STRING}
?那就用修饰符吧,伙计们,多少不是很多?目前我正在看一个292行的大项目。@zerkms很多是主观的,但对我来说,大多数人不需要超过10行。我看到的唯一例外是,如果您手动将每个URL重写为另一个URL(即没有regex,只有somefile.html->dir/dir2/otherfile.html)@zerkms以供参考drupal项目(),一个相当大的项目,有大约15条重写规则,其中一半处理压缩的缓存文件。除去注释的整个过程是45行,其中大多数都配置了非重写的东西,比如php和缓存,所有这些都是为了让Drupal使用相同的公约数。因此,简而言之,要完成工作实际上不需要什么规则。谢谢大家的建议。我确实找到了一个更好的方法,将我的经历浓缩成4次重写。