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 dsdsfdsf.somesite.com, to be automatically transferred to somesite.com.

To begin with, I tried setting up an A record with *.somesite.com 1.1.1.1. 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?
  •  

alex.thomson

You instructed the browser and other "clients" to direct any subdomain requests to the server with IP address 1.1.1.1. 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 (.*) https://site.name [R=301,L]

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

_XyJIuGaN_

Add an A record to the domain's DNS records, f.e.  *.example.com . A 10.0.0.1
Where example.com is your domain, 10.0.0.1 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 ^(.*)$ http://example.com/$1

Where example.com is your domain
  •