Redirect the entire domain

Can I redirect the entire domain to another?

I want him to redirect this path:

domain.com/something --> www.domain.eu/something sub.domain.com/folder/file.type --> sub.domain.eu/folder/file.type super.mega.sub.domain.com --> super.mega.sub.domain.eu 

(for any subdomain and everything after /.)

I only have access to the com domain.

So far, I have invented this code for the .htaccess file:

 RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} !^domain.com$ [OR] RewriteCond %{HTTP_HOST} ^domain.com$ [OR] RewriteCond %{HTTP_HOST} ^www.domain.com$ RewriteRule (.*)$ http://www.domain.eu/$1 [R=permanent,L] 

But it works like:

 sub.domain.com/something --> www.domain.eu/sub/something 

So this is wrong. Any help please? Thank you very much.

+4
source share
3 answers

Try this instead of what you have:

 RewriteEngine On # for main domain RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC] RewriteRule ^(.*)$ http://www.domain.eu/$1 [L,R=301] # for all subdomains RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC] RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com$ [NC] RewriteRule ^(.*)$ http://%1.domain.eu/$1 [L,R=301] 
+1
source

OK. I assume that you want to redirect the entire domain to another, and not just one page.

So just write the following lines in your htaccess file

Rewriteengine on

RewriteCond% {HTTP_HOST} ^ yourolddomain.com $ [OR]

RewriteCond% {HTTP_HOST} ^ www.yourolddomain.com $

RewriteRule (. *) $ Http://www.yournewdomain.com/ $ 1 [R = 301, L]

0
source

Usually I just create an index.html file and redirect it with meta tags:

 <meta http-equiv="refresh" content="0;URL=http://www.newdomain.ext"> <meta http-equiv="refresh" content="0;URL=http://subdomain.newdomain.ext"> 
0
source

Source: https://habr.com/ru/post/1444412/


All Articles