将除部分内容之外的所有内容重定向到新 URL?

发布于 2025-01-02 03:18:36 字数 304 浏览 3 评论 0原文

我正在移动网站,并且想对除部分 URL 之外的所有 URL 进行 301 重定向,

如下所示:

oldsite.com/* -> www.newsite.com

oldsite.com/special/article/to/redirect -> www.newsite.com/fancy/blah

因此,我想将一些内容重定向到特定页面,但其余所有内容都应该转到根目录,这如何在 .htaccess 中完成?

I am moving site and I want to do a 301 redirect on all but some of the URLs,

Like this:

oldsite.com/* -> www.newsite.com

oldsite.com/specific/article/to/redirect -> www.newsite.com/fancy/blah

So there are a few things I want to redirect to specific pages but all the rest should just goto root, how can this be done in .htaccess?

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

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

发布评论

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

评论(2

梦明 2025-01-09 03:18:36

将以下内容添加到旧网站根目录中的 .htaccess 文件中。

#place your specific redirects first 
Redirect 301 /specific/article/to/redirect http://www.newsite.com/fancy/blah

RewriteEngine on

#then your general redirect all to new site last
RewriteRule ^ http://www.newsite.com%{REQUEST_URI} [L,R=301]

Add the following to the .htaccess file in the root directory of your old site.

#place your specific redirects first 
Redirect 301 /specific/article/to/redirect http://www.newsite.com/fancy/blah

RewriteEngine on

#then your general redirect all to new site last
RewriteRule ^ http://www.newsite.com%{REQUEST_URI} [L,R=301]
感悟人生的甜 2025-01-09 03:18:36

如果您只有一个需要豁免的 URL,可以使用 RedirectMatch。

RedirectMatch permanent !/specific/article/to/redirect http://www.newsite.com

对于多个 URL,您可能最好使用 mod_rewrite 和外部 rewritemap 列出了要豁免的网址。

There's RedirectMatch if you've got only one URL that needs to be exempted.

RedirectMatch permanent !/specific/article/to/redirect http://www.newsite.com

for multiple URLs, you'd probably be better off with mod_rewrite and an external rewritemap that lists the urls to be exempted.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文