Redirect from all non-existent subdomains to the main site

Started by autorenta, Aug 08, 2022, 04:47 AM

Previous topic - Next topic

autorentaTopic starter

Could you please explain to me the steps involved in configuring redirects for non-existent subdomains to the main domain? Essentially, I want any link with a non-existent subdomain, like, to be automatically transferred to

To begin with, I tried setting up an A record with * However, this resulted in a 404 error being displayed rather than redirecting to the main domain. It wasn't even possible to modify this error via .htaccess since it is generated by the system.

I then attempted various options in the .htaccess file, but none of them seemed to work with subdomains. Do you have any suggestions on how to overcome this challenge?


You instructed the browser and other "clients" to direct any subdomain requests to the server with IP address However, for this to work properly, the web server has to be configured appropriately. This entails pointing all subdomains to a specific folder. A simple unconditional redirect to the main domain will suffice if an arbitrary folder is used. On the other hand, if a root document from the main domain is specified, the following code can be utilized:

RewriteCond %{HTTP_HOST} \.site\.name$
RewriteRule (.*) [R=301,L]

It is important to ensure that these lines are placed above the other internal rules, immediately after RewriteEngine On.


Add an A record to the domain's DNS records, f.e.  * . A
Where is your domain, is the IP address your domain links to. support of the hosting provider whose services you use.

open the file. htaccess, which must be located in website directory, write

RewriteEngine On
RewriteCond %{HTTP_HOST} !^example\.com$
RewriteRule ^(.*)$$1

Where is your domain