将分层(嵌套)URL 重定向到平面 URL

发布于 2024-12-23 06:38:14 字数 313 浏览 4 评论 0原文

第一个问题在这里:)。

我们当前运行的站点使用分层(嵌套)URL,例如 example.com/folder/page/

我们现在更喜欢平面 URL,例如 example.com/page/

我们的 CMS 可以轻松地允许切换到指定平面 URL 的页面。但是,它不处理来自旧分层 URL 的重定向。看起来需要在 .htaccess 文件中处理。

有 250 多个页面,因此最好使用能够处理所有重定向的代码,而不是为每个 URL 执行重定向 301。

任何人都可以提供一些 .htaccess 代码或为我指出正确的方向以实现重定向吗?

First question here :).

A site we run currently uses hierarchical (nested) URLs e.g. example.com/folder/page/

We would now prefer flat URLs e.g. example.com/page/

Our CMS can easily allow a switch to pages being given flat URLs. However it does not handle the redirects from the old hierarchical URLs. It looks like it needs to be handled in the .htaccess file.

There are 250+ pages so it would be preferable to have code that would handle all the redirects rather than doing a redirect 301 for each URL.

Can anyone provide some .htaccess code or point me in the right direction to achieve the redirects?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

老娘不死你永远是小三 2024-12-30 06:38:14

这可能不是世界上最有效的事情,但我在我的博客上使用一个大的 .htaccess 文件执行此操作,其中包含:

RedirectMatch permanent ^/old/url http://example.com/new-url

如果您可以编辑主 Apache 配置文件而不是使用 .htaccess 文件,使用 重定向 而不是RedirectMatch (在 .htaccess 文件中使用更容易,因为,如果我记得的话,它会与相对于 .htaccess 文件的 URL 进行匹配……其他的……当涉及到Redirect时,但我可能是错的。)

It's probably not the most efficient thing in the world, but I do this on my blog using a big .htaccess file containing:

RedirectMatch permanent ^/old/url http://example.com/new-url

If you can edit the main Apache config file instead of using .htaccess files, it will likely be more efficient to use Redirect instead of RedirectMatch (which is easier to use inside .htaccess files because, if I recall, it matches against the URL relative to the .htaccess file instead of… something else… when Redirect is involved. But I could be wrong about that.)

慵挽 2024-12-30 06:38:14

您可以在 .htaccess 中的 $DOCUMENT_ROOT 下尝试以下代码:

Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteOptions MaxRedirects=5

RewriteRule ^folder(/page/.*)$ $1 [NC,L,R=301]

You can try this code in your .htaccess under $DOCUMENT_ROOT:

Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteOptions MaxRedirects=5

RewriteRule ^folder(/page/.*)$ $1 [NC,L,R=301]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文