Is there any way to access any subdomain does not exist redirect to main domain?

Is there a way to do that when you access an unregistered subdomain redirect you to the main domain?

http://example.example.com/ to http://www.example.com/

Or at least display an error message stating that the subdomain does not exist

@Madirex You mean you want to redirect unregistered subdomains to your main domain.

I think this is what he is asking @akhilkumar332

If this is the case, the by default the url will not load.
When you try to load any unregistred subdomain with your domain, you’ll get an error.(ERR_NAME_NOT_RESOLVED).

ERR_NAME_NOT_RESOLVED Error,

I would like to redirect, and if you can not create a custom error

Something that says “Subdomain not registered, click here to go to the main domain”

I doubt if it is possible,
I’ll check and get back to you.

Something new? :frowning:

This should be possible by adding this code to your .htaccess file:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.+)\.mydomain\.com$   [NC]
RewriteCond %{HTTP_HOST} !^www\.mydomain\.com$  [NC]
RewriteRule ^ http://mydomain.com/suberror  [L,R]

And replace mydomain.com with your domain

Doesn’t Work:

ERR_NAME_NOT_RESOLVED

D:

Did you replace mydomain.com with your current domain?

Yes

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.+)\.circuitsbm\.com$   [NC]
RewriteCond %{HTTP_HOST} !^www\.circuitsbm\.com$  [NC]
RewriteRule ^ http://circuitsbm.com/suberror  [L,R]

Try this

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.+)\.circuitsbm\.com$   [NC]
RewriteCond %{HTTP_HOST} !^www\.circuitsbm\.com$  [NC]
RewriteRule ^ http://circuitsbm.com/ [L,R]

///////Didnt works D:///////

I’ll try to find a new code then :slight_smile:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

# the following three lines will work for all subdomains
RewriteCond %{HTTP_HOST} !^circuitsbm\.com$ [NC]
RewriteCond %{HTTP_HOST} !^www\.circuitsbm\.com$ [NC]
RewriteRule . "http://www.circuitsbm.com/" [R=301,L]

# the following two lines will redirect non-www to www version of the domain
RewriteCond %{HTTP_HOST} ^circuitsbm\.com$
RewriteRule ^(.*)$ "http://www.circuitdbm.com/$1" [R=301,L]

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Dint work, the same error :frowning:

I think that’ll be impossible then :slight_smile:
Sorry for that