【发布时间】:2017-01-24 19:11:34
【问题描述】:
我有大量链接 - 示例:
tempfile-1.php
tempfile-2.php
tempfile-3.php
...
tempfile-255.php
我需要做的是将文件分别重定向到:
temp-file-1.php
temp-file-2.php
temp-file-3.php
...
temp-file-255.php
我知道如何一一重写,但这不是解决方案。 你能帮忙在通配符规则/条件中重写这些类型的链接吗? 非常感谢。
【问题讨论】:
-
@anubhava - 请您看一下这个
-
使用正则表达式。这方面的文章很多。即searchenginepeople.com/blog/…
-
是的,这个话题有很多文章,仍然有问题要解决
-
重写还是重定向?
-
我不知道 mod-rewrite,但我可以给你 sed 中的正则表达式。显然,“temp”或“file”必须是一个常数。我假设常量是“temp”而不是“file”。这个表达式 ... sed 's/^temp(.*-)(.*).php/temp-\1\2/' ... 会做你想做的事。 $ cat links.txt tempfile-1.php tempfile-2.php tempfile-3.php tempfile-255.php $ cat links.txt | sed 's/^temp(.*-)(.*).php/temp-\1\2/' temp-file-1 temp-file-2 temp-file-3 temp-file-255
标签: regex apache .htaccess url mod-rewrite