.htaccess - .htaccess 文件中超过 4,000 条重定向 301 行

标签 .htaccess cpanel

我很快就会重新设计我的网站,所有 URL 都在改变。这是我到目前为止整理的内容 http://cricketweb.net/new-design%20htaccess

我所做的一些研究表明,.htaccess 文件中的这么多行会大大降低性能。

我问过我的托管服务提供商,他们说:

"Your info is correct, adding this many redirects to your .htaccess will slow down the load time of your site pretty significantly. Adding these to the Apache conf unfortunately isn't a good idea on a cPanel server. cPanel makes edits to the conf file regularly and might not play nice with your edits. I'd recommend reevaluating the rewrite patterns first. For example, if domain1.com has folders a, b, and c and you want to send visitors to domain1.com/a to domain2.com/a, and the same for b and c, this could be accomplished with 1 rewrite rule. Unfortunately, if the URLs differ in inconsistent ways, like if you want to send visitors to domain1.com/a to domain2.com/asdf and visitors to domain1.com/b to domain2.com/zxcv, we may need to look into editing your apache preconf files with special rules for this domain, so please let me know if you will be able to shrink the number rules by consolidating them or not."

问题是我不知道如何整合这些 301。

有人根据http://cricketweb.net/new-design%20htaccess 有什么建议吗?

最佳答案

无法优化类型 A -> B 的关系。

但是当有可能找到重复模式时,
A1 -> B, A2 -> B, A9999 -> B
或 A1 -> B1,A2 -> B2,A9999 -> B9999
你真的可以减少行数。

例子:(同类型超过150行)

Redirect 301 \cricketgames\commercial\brianlaracricket05\demo100.php http://www.cricketweb.net/game/brian-lara-international-cricket-2005/
Redirect 301 \cricketgames\commercial\brianlaracricket05\demo101.php http://www.cricketweb.net/game/brian-lara-international-cricket-2005/
Redirect 301 \cricketgames\commercial\brianlaracricket05\demo102.php http://www.cricketweb.net/game/brian-lara-international-cricket-2005/

可以简化为:(1行)

RewriteRule ^cricketgames/commercial/brianlaracricket\d+/demo\d+\.php$ http://www.cricketweb.net/game/brian-lara-international-cricket-2005/ [NC,R=301]

其他例子(超过160行):

Redirect 301 \cricketgames\commercial\internationalcricketcaptain2000\screenshot5.php http://www.cricketweb.net/game/international-cricket-captain-2000/
Redirect 301 \cricketgames\commercial\internationalcricketcaptain2006\screenshot13.php http://www.cricketweb.net/game/international-cricket-captain-2006/
Redirect 301 \cricketgames\commercial\internationalcricketcaptain2009\screenshot14.php http://www.cricketweb.net/game/international-cricket-captain-2009/

可以简化为:(1行)

RewriteRule ^cricketgames/commercial/internationalcricketcaptain(20\d\d)/screenshot\d+\.php$ http://www.cricketweb.net/game/international-cricket-captain-$1/ [NC,R=301]

而且你的文件里有那么多同类型的案例。

然后您还可以选择将文件分成几个部分(重写),以避免测试从 URL 开头删除的所有行。 例如,这可以将测试数量除以 20 到 30,只需进行中间重写。

关于.htaccess - .htaccess 文件中超过 4,000 条重定向 301 行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28225507/

相关文章:

.htaccess - Laravel 4.2 应用上传直播服务器后发生不必要的重定向

postgresql - 非英语语言的 en_us.UTF8 归类

php - 如何在 cPanel 管理的服务器上安装 MySQLi?

.htaccess - .htaccess 中的 AuthName 未显示在 Chrome 中

mysql - 如何在cPanel中查找服务器名称?

linux - 是否有任何包含 Cronjob 列表的文件?

wordpress - 需要将 WordPress 帖子分类到子文件夹中,而不需要在子文件夹中单独安装 WordPress

jquery - 加快 HTML 网站速度的方法?

node.js - 找不到页面 "/"路由

php - SSL 固定内容,为什么不返回 site_url(),在 https 方案中