Last updated on November 17th, 2015 at 05:40 am

Simple htaccess trick to redirect all subdomains except some to the main URL.

Here we have a website named So we dont want to redirect 2 subdomains namely and to the main URL and want every other subdomain to be redirected then please follow the below rules. Make sure you modify it according to your requirement.

Rewrite condition format

Complete rule to be added to the .htaccess file.

RewriteCond %{HTTP_HOST} !^demo\.anywebsite\.com$ [NC]
RewriteCond %{HTTP_HOST} !^dev\.anywebsite\.com$ [NC]
RewriteRule ^(.*)$$1 [L,R=301]

Please make sure you make a backup of the existing htaccess file before proceeding.

Leave a Reply

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