来自 htaccess 的批量 301 重定向
我有一个电子表格,其中包含 404 错误链接列及其各自的 301 重定向。 例如)
404 error page 301 redirect
http://www.abc.com/1.php http://www.abc/com/2.php
.............. ............
电子表格有大约 1000 多个链接。
apache 配置或 htaccess 中有什么方法可以处理批量 301 重定向吗?
I have spreadsheet which has column of 404 error link and its respective 301 redirects.
for e.g)
404 error page 301 redirect
http://www.abc.com/1.php http://www.abc/com/2.php
.............. ............
The spreadsheet has around 1000+ links.
Is there any way in apache config or htaccess where can I handle bulk 301 redirects?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
批量设置的最佳方法是 mod 中的 RewriteMap 指令-改写。请注意,这在 .htaccess 文件中不起作用。您需要在真正的 apache 配置文件中编辑它(好消息是这比 .htaccess 动态配置要快)。
首先检查
txt:
关键字。可能是这样的:
当你让它正常工作时,将 302 转换为 301,并使用
dbm:
关键字(和httxt2dbm
httxt2dbm)将 txt 文件转换为更快的哈希映射。 code> 命令,但这在链接的文档中进行了解释)。The best way for a Bulk setting is the RewriteMap directive in mod-rewrite. Note that this will not work in a .htaccess file. You'll need to edit it in a real apache configuration file (and the good news is that will be really faster than a .htaccess dynamic configuration).
Check the
txt:
keyword first.May be something like that:
When you'll get it working well transform the 302 in 301, and convert the txt file to an faster hashmap with the
dbm:
keyword (and ahttxt2dbm
command, but that's explained in the linked doc).正如 regilero 所说,RewriteMap 确实是要走的路。但是,我无法理解他的代码应该如何工作,也无法让它工作。一个问题是它假设没有进一步的重写(缺少 [L]) 这确实有效:
在 apache 配置中(在 .htaccess 中不起作用):
在 .htaccess 中(也适用于 apache 配置):
在 redirects.txt 中(注意:斜杠不是可选的)
我不确定切换到 dbm 是否值得额外的麻烦。
如http://httpd.apache.org/docs/2.2/所述mod/mod_rewrite.html#rewritemap ,查找无论如何都会缓存在内存中。
RewriteMap is indeed the way to go as stated by regilero. However, I couldn't understand how his code is supposed to work neither could I get it to work. One problem is that it assumes that there are no further rewrites (missing [L]) This does work:
In the apache config (does NOT work in .htaccess):
In .htaccess (also works in apache config):
In redirects.txt (Note: Slashes are NOT optional)
I'm not sure switching to dbm is worth the extra hassle.
As stated on http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewritemap , the lookup is cached in memory anyway.
在 404.php 中包含_once此文件 - 确保 404.php 配置为在存在 404 时调用:
表结构:
surl = 源 Url
durl = 目标 Url
include_once this file in 404.php - make sure 404.php is configured to be called when there is 404 :
Table structure:
surl = Source Url
durl = Destination Url