如何根据内容自动定义 .htaccess 重定向
我正在使用
grep -HEri "Title\:(content)" ./www.livesite.com/ > Livesite.txt
和
grep -HEri "Title\:(content)" ./www.devsite.com/ > Devsite.txt
来查找具有可以通过正则表达式指定的匹配或相似内容的路径对。当 ^/example_found_live_path.html
中的内容与 ^/ Different/found_devsite_path
中的内容匹配时,我想向开发站点的 .htaccess 文件添加一行,创建 301 重定向从实时站点的路径到开发站点上找到的路径,如下所示:
redirect 301 ^/example_live_path.html ^/different/devsite_path
期望的结果是,在启动时,所有搜索引擎条目和当前实时站点页面的链接都重定向到具有匹配标题的页面在开发站点中。 我觉得这是 sed、grep 和 xargs 的工作,但不知道如何构建命令。 是不是像:
grep -HEri "Title\:(content)" ./www.livesite.com/ | xargs 'echo %1; grep -HEri %2 ./www.devsite.com' | xargs 'sed "$a\nredirect 301 \^%1 \^%2\n' .htaccess
提前致谢!
I am using
grep -HEri "Title\:(content)" ./www.livesite.com/ > Livesite.txt
and
grep -HEri "Title\:(content)" ./www.devsite.com/ > Devsite.txt
to find pairs of paths which have matching or similar content I can specify by regex. When the content from ^/example_found_live_path.html
matches that in ^/different/found_devsite_path
, I want to add a line to the dev site's .htaccess file, creating a 301 redirect from the live site's path to the path found on the dev site, that looks like this:
redirect 301 ^/example_live_path.html ^/different/devsite_path
The desired result is that on launch, all search engine entries and links to pages from the current live site redirect to pages with matching titles in the dev site.
I feel like this is a job for sed, grep, and xargs but don't know how to structure the command.
Is it like:
grep -HEri "Title\:(content)" ./www.livesite.com/ | xargs 'echo %1; grep -HEri %2 ./www.devsite.com' | xargs 'sed "$a\nredirect 301 \^%1 \^%2\n' .htaccess
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您已经通过运行以下命令获得了两个文件列表:
并得到: (每个找到的文件可能有多个匹配项)
连接结果应该是:
这是在匹配内容上内连接两个列表的脚本:
结果应该是:
嗯..祝你好运!
You already had the two file lists by running:
and got: (there maybe multiple matchings for each found file)
The join result should be:
Here is the script to inner-join the two lists on the matching content:
and the result should be:
Umm.. good luck!