将所有动态 URL 从旧站点重定向到单个静态 URL
几年前,我们有一个旧的 Coldfusion 网站,我最近意识到有一些旧链接仍然存在,导致 404 错误。我不知道任何页面上有什么,我只想将它们重定向到新的静态页面。我们的新网站是一个启用了 SEF URL 的 Joomla 1.5 网站。
旧的 URL 如下所示:http://www.example.com/content.cfm?id=2010
,其中 URL 之间的唯一区别是 id=< 之后的数字/代码>。 我想将任何以
content.cfm
开头的 URL 重定向到静态页面 http://www.example.com/oops-thats-an-old-page
其中列出了一些有用的链接来查找他们正在寻找的内容。
我使用 .htaccess 文件中的以下代码成功完成了此操作:
RewriteCond %{QUERY_STRING} id=
RewriteRule (.*) http://www.example.com/$1? [R=301]
RewriteRule ^content\.cfm$ /oops-thats-an-old-page [R=301,L]
我是重写 URL 的新手,我不确定这是最好的方法。我还担心它可能会阻止我不知道的非 sef joomla URL,因为它们中也有 id=
。
我可以根据是否以 content.cfm
开头来进行重写吗?
We had an old coldfusion website a couple of years ago and I recently realized there are some old links still floating around causing 404 errors. I don't know what was on any of the pages and I just want to redirect them to a new static page. Our new site is a Joomla 1.5 site with SEF URLs turned on.
An old URL would look like this: http://www.example.com/content.cfm?id=2010
where the only difference between the URLs would be the number after id=
.
I want to redirect any URL that begins with content.cfm
to a the static page http://www.example.com/oops-thats-an-old-page
which lists some helpful links to find what they are looking for.
I am successfully accomplishing this with the following code in the .htaccess file:
RewriteCond %{QUERY_STRING} id=
RewriteRule (.*) http://www.example.com/$1? [R=301]
RewriteRule ^content\.cfm$ /oops-thats-an-old-page [R=301,L]
I'm new to rewriting URLs and I'm not sure this is the best way to do it. I am also concerned that it may brake non-sef joomla URLs that I am not aware of because they also have the id=
in them.
Can I make the rewrite conditional on whether or not it begins with content.cfm
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当查询包含
id=
时,第一条规则将已应用。如果您不希望这样做,而是仅在请求包含id=
的查询的/content.cfm
时重定向,请尝试以下规则:The first rule will already be applied when the query contains
id=
. If you don’t want that but rather redirect only if/content.cfm
with query containingid=
was requested, try this rule: