Redirect Subdomain to Subdirectory

To redirect a subdomain to a subdirectory, use following .htaccess code.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com
RewriteRule ^(.*)$ subdomains/%1/$1 [L,NC,QSA]

Redirect Subdirectory to Subdomain

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$
RewriteRule ^/?subdomain/(.*)$ https://subdomain.example.com/$1 [R=301]

See htaccess

Need help with Linux Server or WordPress? We can help!

Leave a Reply

Your email address will not be published. Required fields are marked *