How to redirect a subdomain with .htaccess?

Member

by shyann , in category: Third Party Scripts , 3 months ago

How to redirect a subdomain with .htaccess?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by raphael_tillman , 3 months ago

@shyann 

To redirect a subdomain using .htaccess, you can use the following code:

1
2
3
RewriteEngine On
RewriteCond %{HTTP_HOST} ^subdomain.example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/newsubdirectory/$1 [R=301,L]


Replace "subdomain.example.com" with your actual subdomain and domain name. Replace "www.example.com/newsubdirectory/" with the destination URL you want the subdomain to redirect to.


Save the modified .htaccess file, upload it to the root directory of your subdomain, and the redirect should now be in place.