简体   繁体   English

RedirectMatch 301的同一页面URL到多个TLD

[英]RedirectMatch 301s same page URL to multiple TLDs

We're working on a magento store at the moment where multiple 301 redirects have previously been implemented. 目前,我们正在一家magento商店中工作,该商店先前已实现了多个301重定向。 The original .htaccess file has lots of rules in such as the following: 原始的.htaccess文件具有很多规则,例如:

RedirectMatch 301 ^/original-page.html http://www.yourdomain.co.uk/our-new-directory/new-page.html
RedirectMatch 301 ^/original-page2.html http://www.yourdomain.co.uk/our-new-directory/new-page2.html 
RedirectMatch 301 ^/original-page3.html http://www.yourdomain.co.uk/our-new-directory/new-page3.html

The website has now had a new TLD setup, so if you visit http://www.yourdomain.de/original-page.html , you're getting redirected to http://www.yourdomain.co.uk/our-new-directory/new-page.html . 该网站现在有了新的TLD设置,因此,如果您访问http://www.yourdomain.de/original-page.html ,您将被重定向到http://www.yourdomain.co.uk/our- new-directory / new-page.html

What I want to do is have it so that we have the following: 我想要做的就是拥有它,以便我们具有以下功能:

Someone types in: 有人输入:

http://www.yourdomain.co.uk/original-page.html and gets redirected to http://www.yourdomain.co.uk/our-new-directory/new-page.html

AND

http://www.yourdomain.de/original-page.html and gets redirected to http://www.yourdomain.de/our-new-directory/new-page.html

Essentially, the redirect should take into account the TLD that the user is on. 从本质上讲,重定向应考虑用户所在的TLD。 The main reason for this is that many pages on the website have URLs where they've been 301 redirected. 造成这种情况的主要原因是,网站上的许多页面都有301重定向到的URL。

Any assistance on this would be brilliant. 在这方面的任何帮助将是出色的。

Kind regards, Lewis 亲切的问候,刘易斯

Place this code in your DOCUMENT_ROOT/.htaccess file: 将此代码放在您的DOCUMENT_ROOT/.htaccess文件中:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^www\.yourdomain\. [NC]
RewriteRule ^original-page\.html$ http://%{HTTP_HOST}/our-new-directory/new-page.html [R=301,L]

You can just remove the hostname part of your redirects: 您只需删除重定向的主机名部分即可:

RedirectMatch 301 ^/original-page.html /our-new-directory/new-page.html
RedirectMatch 301 ^/original-page2.html /our-new-directory/new-page2.html 
RedirectMatch 301 ^/original-page3.html /our-new-directory/new-page3.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM