subdomain error redirects to main site using htaccess

Avatar
  • Answered
Any non existant subdomain gets redirected to my hosts site

would like to redirect from not existing subdomains to error page or to main domain. I have a lot of subdomains and they are created and deleted dynamically so I do not control the process and do not know what exactly subdomains are created or deleted right now.

If one user deletes his subdomain I would like to redirect visitors to main domain or just show error page with custom message, the same like it's made by blogspot.com:

Lets say if you type any not existing subdomain it shows you error page that says that subdomain page does not exist
Avatar
JacobIMH
Hello, This is going to depend on the type of hosting that you have your website running on. It sounds like you need to setup a wildcard subdomain and DNS record if the DNS for each subdomain is getting created as your users create their accounts. If you already have wildcard subdomains and DNS setup, then you might need to place a 301 redirect via .htaccess using something like the following code: .htaccess
RewriteEngine on
RewriteCond %{HTTP_HOST} ^subdomain.example.com [NC]
RewriteRule ^(.*)$ http://example.net/ [L,R=301,NC]
That code would redirect subdomain.example.com to the main example.com website. Please let us know if you have any further questions, and if you can share any more information about the type of hosting you're using and if you're using a particular type of software as well to manage your sites. - Jacob