将所有动态 URL 从旧站点重定向到单个静态 URL

发布于 2024-08-31 07:40:05 字数 742 浏览 1 评论 0原文

几年前,我们有一个旧的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忘东忘西忘不掉你 2024-09-07 07:40:05

当查询包含 id= 时,第一条规则将已应用。如果您不希望这样做,而是仅在请求包含 id= 的查询的 /content.cfm 时重定向,请尝试以下规则:

RewriteCond %{QUERY_STRING} id=
RewriteRule ^content\.cfm$ /oops-thats-an-old-page? [R=301,L]

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 containing id= was requested, try this rule:

RewriteCond %{QUERY_STRING} id=
RewriteRule ^content\.cfm$ /oops-thats-an-old-page? [R=301,L]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文