压缩 .htaccess 文件
我有一个 htaccess 文件,其中包含 3,000 多行,这主要归功于我从旧电子商务网站设置的 301 重定向。该文件大小为 323kb,我担心它会成为加载时间和转换的负担。
是否有任何可用的方法可以将文件压缩(缩小?)为更小的大小,或者有人提供更好的想法来处理 301 重定向?
I've got a htaccess file which contains over 3,000 lines mainly thanks to 301 redirects I have setup from my old ecommerce site. The file is 323kb in size and I'm worried it's going to be a burden for load times and therefore conversions.
Is there anything available that can compress (minify?) the file into a smaller size or someone offer a better idea to handle the 301 redirects?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果重定向是简单的重定向,即
url1
到url2
,没有正则表达式等,并且您可以访问 httpd.conf,那么您可以使用 RewriteMap 用于所有重定向,并且 .htaccess 中可能只有 1 条规则处理这些。来自 RewriteMap 文档
If the redirects are simple redirects i.e.
url1
tourl2
, no regex etc, AND you have access to httpd.conf, then you could use a RewriteMap for all the redirects and possibly have just 1 rule in your .htaccess to handle these.From the RewriteMap documentation
您可以指定一些正则表达式来对所有这些重定向进行分组/匹配吗?然后,这提供了两个选项来执行此操作:
[R=301]
标志使用一组(希望较小的)RewriteRule
语句。第二个方法是将此重定向移至重定向器脚本中,您可以在其中使用 PHP 逻辑将旧电子商务 URI 解码为其当前格式,然后发出包含 301/302 状态和位置的响应:指向当前 URI 。这还需要您将旧电子商务 URI 全部重写为此重定向器脚本,例如
如果没有一些示例,我无法给出更具体的答复。对不起。
Can you specify some regular expressions to group / match all of these redirects? This then offers two options for doing this:
RewriteRule
statements using the[R=301]
flag.The second is to move this redirection into a redirector script where you use, say, PHP logic to decode the legacy ecommerce URI into its current format then issue a response with and 301/302 status and Location: pointing to the current URI. This would also need you to do a catch-all rewrite of the legacy ecommerce URIs to this redirector script, e.g.
Without some examples, I can't give a more specific reply. Sorry.
我以前遇到过一些这样的情况,大多数时候你可以用 RewriteRules 替换重定向语句。例如,如果您的网址从:
到此:
您可以通过如下重写来获取它:
这仍然会导致 301 重定向,因此爬虫仍会知道这是永久移动。
I've had some of these cases before, most of the times you can replace the redirect statments with RewriteRules. For example, if your URL's went from:
To this:
You can fetch it with a rewrite like this:
This will still result in a 301 redirect, so crawlers will still know it's a permanent move.