简体   繁体   中英

Redirect all pages from one domain to current domain

I have multiple subdomains, for example:

uk.domain.com
us.domain.com
eu.domain.com

And I need to redirect all of these subdomains (and any pages that the user tries to access on those subdomains) to:

www.domain.com

Example:

uk.domain.com/page1 -> www.domain.com/page1
uk.domain.com/page2 -> www.domain.com/page2

us.domain.com/page1 -> www.domain.com/page1
us.domain.com/page2 -> www.domain.com/page2

eu.domain.com/page1 -> www.domain.com/page1
eu.domain.com/page2 -> www.domain.com/page2
...etc

Is there a rule that can apply to all URLs on each of the subdomains and redirect them to the main domain, with the page in the URL intact, as above?

I have tried example here , but that did not work

From the control panel of your hosting provider, find an option for permanent redirection. The sample below is the page to mage redirections. Alternatively, edit the.htaccess file in each of the subdomains and add the line below.

Redirect 301 / http://yourdomain.com/

在此处输入图像描述

Solved. This works

RewriteCond %{HTTP_HOST} ^uk\.something\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/?$ [NC]
RewriteRule ^(.*)$ https://www.somethingelse.com/$1 [R=301,L]

However it needed to be at the top of my .htaccess, since I had other rules that were interfering with it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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