逐个 - 重定向页面从旧到新的网站 [英] Redirect pages from old to new site - one by one

查看:175
本文介绍了逐个 - 重定向页面从旧到新的网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想重定向一个页面到页面的基础一种新的领域,从几个老域名的网页,那就是:

I'm trying to redirect pages from several old domains on one new domain on a page-to-page basis, that is:

第1页: http://www.example.org/default.asp?id = 1 重定向到 http://www.example2.org/newpage.html 第2页: http://www.example2.org/default.asp?id=2 重定向到 http://www.example.org/contact.html

page 1: http://www.example.org/default.asp?id=1 redirects to http://www.example2.org/newpage.html page 2: http://www.example2.org/default.asp?id=2 redirects to http://www.example.org/contact.html

...等等。每个旧的网页重定向到一个特定的新的一页。

...and so on. Every old page will redirect to a specific new page.

我试图写的东西在.htaccess沿着线

I have tried to write something in .htaccess along the lines of

Redirect 301 http://www.example.org/default.asp?id=1 h-tp://www.example.org/newpage.html
Redirect 301 http://www.example2.org/default.asp?id=2 h-tp://www.example.org/contact.html

但至今没有运气。 mod_alias中启用了...

But no luck so far. mod_alias is enabled...

我也尝试过使用的RewriteCond和重写规则是这样的:

I also tried using RewriteCond and RewriteRule like this:

RewriteCond %{HTTP_HOST} example.org
RewriteRule default.asp?id=1 http://www.example.org/newpage.html [NC,L,R=301]
...

在换句话说:我想做一个页逐页的重定向基于身份的别名为基础以及合并三个站点/域到一个网站

In other words: I want to do a page-by-page redirect from id-based to alias-based along with a merge of three sites/domains into one site.

我希望有一个有用的解决方案。在此先感谢!

I hope there is a useful solution. Thanks in advance!

推荐答案

的的 重定向 指令并只与的 URL路径而不是URL的主机或查询。

The Redirect directive does only work with the URL path but not the host or query of the URL.

但它有可能与 mod_rewrite的

RewriteCond %{HTTP_HOST} =example.org
RewriteCond %{QUERY_STRING} =id=1
RewriteRule ^default\.asp$ http://www.example.org/newpage.html [NC,L,R=301]

和作为已经在评论中说,您可以使用重写地图的ID到别名映射:

And as already said in the comments, you can use a rewrite map for the ID-to-alias mapping:

1 foo-page
2 bar-page
3 baz-page
…

RewriteMap指令声明(这里简单的纯文本文件):

The RewriteMap declaration (here a simple plain text file):

RewriteMap id-to-alias txt:/absolute/file/system/path/to/id-to-alias.txt

和最终的应用程序:

RewriteCond %{HTTP_HOST} =example.org
RewriteCond %{QUERY_STRING} ^(([^&]*&)*)id=([0-9]+)&?([^&].*)?$
RewriteCond ${id-to-alias:%3}&%1%4 ^([^&]+)&(.*)
RewriteRule ^default\.asp$ http://www.example.org/%1.html?%2 [NC,L,R=301]

这应该也是preSERVER剩余的查询。如果你不希望出现这种情况:

That should also preserver the remaining query. If you don’t want that:

RewriteCond %{HTTP_HOST} =example.org
RewriteCond %{QUERY_STRING} ^(([^&]*&)*)id=([0-9]+)&?([^&].*)?$
RewriteCond ${id-to-alias:%3} .+
RewriteRule ^default\.asp$ http://www.example.org/%0.html? [NC,L,R=301]

这篇关于逐个 - 重定向页面从旧到新的网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆