如何解决使用正则表达式将 301 重定向到具有类似编号的其他 url
我在网站上迁移了我的文章,CMS 系统转换了 URL。
我需要重定向类似于以下内容的 URL:
示例,案例 1。 URL 末尾的相同文章名称和不同编号:
原始网址:https://www.website.com/folder/2087-name-of-the-article
源网址 https://www.website.com/folder/name-of-the-article-r929/
示例,案例 2。 相同的文章名称和 URL 末尾的不同编号,但包含其他子文件夹:
原始网址:https://www.website.com/folder/2087-name-of-the-article
源网址 https://www.website.com/folder0/folder/name-of-the-article-r929/
非常感谢,圣诞快乐。
解决方法
您能否尝试使用所示示例进行以下操作、编写和测试。请确保在测试 URL 之前清除浏览器缓存。如果您想重定向(也更改浏览器中的 URL),请在两个规则中添加带有 R=301
标志的 L
。
RewriteEngine ON
RewriteRule ^folder/name-of-the-article-r929/?$ folder/2087-name-of-the-article [L]
RewriteRule ^folder0/folder/name-of-the-article-r929/?$ folder/2087-name-of-the-article [L]
这认为您想将 http://localhost:80/folder/name-of-the-article-r929/
重写为 http://localhost:80/folder/2087-name-of-the-article
AND http://localhost:80/folder0/folder/name-of-the-article-r929/
到 http://localhost:80/folder/2087-name-of-the-article
。
其中 localhost
可能是您的域名。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。