htaccess 从旧站点重定向到新站点
有一个现有网站 h*tp://www.oldsite.com/ 我需要将其重定向到新网站 h*tp://www.newsite.co.za/。旧站点已在新站点主机帐户上设置为停放域。以下是新闻网站主机的文件结构。 h*tp://www.newsite.co.za/ - /public_html h*tp://www.oldsite.com/ - /public_html/oldsite.com
新站点是对旧站点的完全重组,因此我需要将旧站点的所有索引页面重定向到新站点的一些相应页面。我已成功重定向静态页面,但在动态页面上遇到困难。例如:
h*tp://www.oldsite.com/The_Wine_Shop/Bales_Private_Vintners.aspx?CatID=13&PageID=175&RefPageID=169
to
h*tp://www.newsite.co.za/buy-wine/buy-wine-online/
有几个页面需要根据上面的示例格式进行重定向。进行重定向的最简单方法是什么。我想重定向“The_Wine_Shop”文件夹内的所有文件,包括动态页面,但我不知道如何以这种格式执行此操作。
顺便说一句,这是我的旧网站到新网站索引页面重定向的代码。
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^oldsite\.com [OR]
RewriteCond %{HTTP_HOST} ^www.oldsite\.com
RewriteRule ^/?(.*) http://www\.newsite\.co\.za/$1 [R=permanent,L]
There is an existing site h*tp://www.oldsite.com/ which I need to redirect to the new site h*tp://www.newsite.co.za/. The oldsite is already setup as parked domain on the newsite host account. Below are the file structure of the newsite host.
h*tp://www.newsite.co.za/ - /public_html
h*tp://www.oldsite.com/ - /public_html/oldsite.com
The newsite is a complete restructure of the oldsite, so I needed to redirect all indexed pages of the oldsite to some corresponding pages of the newsite. I have managed to redirect the static pages but Im having a hard time on the dynamic pages. For example:
h*tp://www.oldsite.com/The_Wine_Shop/Bales_Private_Vintners.aspx?CatID=13&PageID=175&RefPageID=169
to
h*tp://www.newsite.co.za/buy-wine/buy-wine-online/
There are several pages that needs to be redirected based on the example format above. What will be the easiest way to do the redirects. I'm thinking to just redirect all the files inside the "The_Wine_Shop" folder including the dynamic pages but I dont have any idea how to do that in this format.
By the way here is the code for my oldsite to newsite index page redirect.
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^oldsite\.com [OR]
RewriteCond %{HTTP_HOST} ^www.oldsite\.com
RewriteRule ^/?(.*) http://www\.newsite\.co\.za/$1 [R=permanent,L]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以向 .htaccess 添加另一个规则集:
这将重定向以
/The_Wine_Shop/
开头的每个页面。如果您想检查请求的 URI 和查询字符串,您可以使用以下内容:
如果您不关心 URL 是大写还是小写,请添加 NC-Flag 到条件。
您还应该将
标记添加到您的新网站
。
更多有关 rel canonical 的信息。
You could add another ruleset to your .htaccess:
This would redirect every page beginning with
/The_Wine_Shop/
.If you want to check the requested URI and the querystring you can go with something like this:
If you don't care if the URL is written upper or lowercase add the NC-Flag to the conditions.
You should also add the
<link rel="canonical" href="http://new-and-correct-url" />
tag to your new sites<head>
.More info on rel canonical.