重定向多个链接的规则
您好,我现在正在迁移一个网站。我有大约 400 个链接需要重定向。我知道如何在 htaccess 中为每个设置设置重定向,但希望设置一条规则。我希望
www.example.com/2011/10/the-news-post
重定向到
www.example.com/home/post/the-news-post
可以这样做吗?如果是的话,代码是什么样的?
谢谢,
格雷戈尔
Hi I'm migrating a site at the moment. I've got about 400 links I need to redirect. I know how to set up a redirect in the htaccess for each one but wold like to set up a rule. I want
www.example.com/2011/10/the-news-post
to redirect to
www.example.com/home/post/the-news-post
Is it possible to do this? And if so what does the code look like?
Thanks,
Gregor
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了保留连字符:
为了将连字符更改为下划线(我也不推荐):
简要说明:
第一条规则匹配任何带有日/月的 URL,后跟包含连字符的文章。它替换连字符,然后重新运行所有重写规则。一旦没有剩下连字符,它将传递到第二条规则,该规则将 URL 重写为 home/articlename。
演示: http://cerebraldonkey.com/mod_rewrite2/2011/5 /某些文章包含几个连字符
In order to preserve the hyphens:
In order to change the hyphens to underscores (which I also don't recommend):
Brief explanation:
The first rule matches any URL with the day/month followed by an article containing a hyphen. It replaces the hyphen, then re-runs all the rewrite rules. Once there are no hyphens left, it will pass through to the second rule, which rewrites the URL as home/articlename.
Demo: http://cerebraldonkey.com/mod_rewrite2/2011/5/some-article-containing-several-hyphens