Mobile app version of vmapp.org
Login or Join
Lengel546

: Redirect *.example.com to example.com I have some valid subdomains in my httpd.conf file. Now how do I redirect anything that's not a valid subdomain to the main website? What I mean is, if

@Lengel546

Posted in: #Domains #HttpdConf #Linux #Redirects #Subdomain

I have some valid subdomains in my httpd.conf file. Now how do I redirect anything that's not a valid subdomain to the main website? What I mean is, if I have a valid subdomain hello.example.com, it should go to hello.example.com and if its blah.example.com which is not a valid subdomain, it should go to example.com. How can I make changes in my httpd.conf file to follow everything I just mentioned?

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Lengel546

2 Comments

Sorted by latest first Latest Oldest Best

 

@Turnbaugh106

If you use Apache and if you have virtual hosts enabled, you got it automagically:


First virtualhost will be default host, which will serve all requests for hosts, not defined as virtual hosts
Known in Apache virtual hosts will be used on request


PS: hello.example.com and blah.example.com are hosts, not subdomains

10% popularity Vote Up Vote Down


 

@BetL925

Setup a new default site in your apache-config and rewrite the url via .htaccess if this default site is called. Maybe something like /var/www/invalid-subdomain/.htaccess:

RewriteEngine on
RewriteBase /
RewriteRule ^$ example.com/ [R,L]


The above example is working well for my apache2 squeeze server.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme