How to redirect subdomain (with all folders and files) to another domain using htaccess?

274 Views Asked by At

I want to redirect subdomain.example.com and all possible URLs accessed by subdomain (like subdomain.example.com/somefolder/somefile.php) to another domain example-two.com. Is it possible with htaccess?

1

There are 1 best solutions below

0
AudioBubble On

For redirects subdomain.example.com/any-address to example-two.com add this rule on top of your subdomain.example.com .htaccess file

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} ^(www\.)?subdomain\.example\.com [NC]
    RewriteRule (.*) http://example-two.com/ [R=301,L]
</IfModule>

For redirects subdomain.example.com/any-address to example-two.com/any-address add this rule on top of your subdomain.example.com .htaccess file

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} ^(www\.)?subdomain\.example\.com [NC]
    RewriteRule (.*) http://example-two.com/$1 [R=301,L]
</IfModule>