KOMPX.COM or COMPMISCELLANEA.COM   

Redirect subdomain to root domain

Redirecting pages of a specific subdomain to root domain pages by means of .htaccess, when subdomain pages may be both with or without www:


RewriteEngine On
RewriteCond %{HTTP_HOST} ^(?:www\.)?subdomain\.(domain\.tld)$ [NC]
RewriteRule ^(.*)$ https://www.domain.tld/$1 [R=301,NC,L]

Commentary

Enable runtime rewriting engine:


RewriteEngine On

If there is a subdomain with or without www:


RewriteCond %{HTTP_HOST} ^(?:www\.)?subdomain\.(domain\.tld)$ [NC]

Then redirect to root domain page:


RewriteRule ^(.*)$ https://www.domain.tld/$1 [R=301,NC,L]

Links

  1. Making www optional in htaccess rule: stackoverflow.com/questions/35124505/making-www-optional-in-htaccess-rule
  2. htaccess redirect page from subdomain to main domain: stackoverflow.com/questions/31477917/htaccess-redirect-page-from-subdomain-to-main-domain
  3. Redirect any sub domain to a page on main domain: stackoverflow.com/questions/8730298/redirect-any-sub-domain-to-a-page-on-main-domain
Web servers
More