Redirect from all non-existent subdomains to the main domain site

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

Previous topic - Next topic

autorentaTopic starter

Hello, can you tell me how to set up redirects from all non-existent subdomains to the main domain?
That is, when going to the example using the link, it was transferred to

I set up A record like *, if before that, when going to and so on, nothing opened at all, now it throws a 404 error, which is not written in .htaccess, but just a system one.
I didn't do anything in the .htaccess file, I tried all the options that I found, as if subdomains didn't react to it at all.


So you told the browser (and other "clients") to apply "for subdomains" to the server with IP =
For right operation, the web server must also be configured. All subdomains need to be referred to one folder. If this is some kind of arbitrary folder, it will be enough to add an unconditional redirect to the main domain in the config. If for some reason a root document from the main domain is specified, something like that:

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

These lines need to be placed above the rest of the internal rules, you can 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