Redirect all possible subdomains to main domain

Keywords: WordPress - Google Cloud Platform - How to - Secure Connections (SSL/HTTPS)

Description:
Hi!
My goal is to redirect all the subdomains to the main domain.
I’d like to rewrite the whole URL instead of a simple redirect because of the SEO,
here’s an example:
subdomain.mydomain.com/hellomydomain.com/hello

Thanks to the bncert tool I have the www to non www configuration.
Here are my apache2/conf/bitnami/bitnami.conf existing rewriting rules:

BEGIN: Enable HTTP to HTTPS redirection
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} !^localhost
RewriteCond %{HTTP_HOST} !^[0-9]+.[0-9]+.[0-9]+.[0-9]+(:[0-9]+)?$
RewriteCond %{REQUEST_URI} !^/.well-known
RewriteRule ^/(.) https://%{SERVER_NAME}/$1 [R,L]
END: Enable HTTP to HTTPS redirection
BEGIN: Enable www to non-www redirection
RewriteCond %{HTTP_HOST} ^www.(.
)$ [NC]
RewriteCond %{HTTP_HOST} !^localhost
RewriteCond %{HTTP_HOST} !^[0-9]+.[0-9]+.[0-9]+.[0-9]+(:[0-9]+)?$
RewriteCond %{REQUEST_URI} !^/.well-known
RewriteRule ^(.*)$ http://%1$1 [R=permanent,L]
END: Enable www to non-www redirection

Thanks is advance for the help!

(I did remove the hashmarks because of the markdown styling)

Hi @gagliottacalzaturena,

As this issue exceeds the scope of this forum. I recommend checking the Apache documentation or a general forum for information about how to create the rewrite rules:

https://httpd.apache.org/docs/

Best regards,
Michiel