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 dsdsfdsf.somesite.com, it was transferred to somesite.com

I set up A record like *.somesite.com 1.1.1.1, if before that, when going to dsdsfdsf.somesite.com 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.
  •  

alex.thomson

So you told the browser (and other "clients") to apply "for subdomains" to the server with IP = 1.1.1.1
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 (.*) https://site.name [R=301,L]

These lines need to be placed above the rest of the internal rules, you can immediately after RewriteEngine On
  •