将分层(嵌套)URL 重定向到平面 URL
第一个问题在这里:)。
我们当前运行的站点使用分层(嵌套)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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这可能不是世界上最有效的事情,但我在我的博客上使用一个大的
.htaccess
文件执行此操作,其中包含:如果您可以编辑主 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:If you can edit the main Apache config file instead of using
.htaccess
files, it will likely be more efficient to use Redirect instead ofRedirectMatch
(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… whenRedirect
is involved. But I could be wrong about that.)您可以在 .htaccess 中的 $DOCUMENT_ROOT 下尝试以下代码:
You can try this code in your .htaccess under $DOCUMENT_ROOT: