I'm not even sure how to search for an answer to this question, so my apologies if already asked.

We have a subdomain setup on the server in the format eg.example.com. Some people are typing in www.eg.example.com. Is there a way of handling the pseudo-subdomain? If so, how?

4 Answers 4


The subdomain is nothing else than a DNS record applied to the root domain. If you consider the root domain example.com, any of the following is a valid subdomain


and even


Then way you create subdomains is creating a DNS record for them, regardless it's a single-level subdomain (foo.example.com) or multilevel subdomain (foo.bar.example.com).

You need to check if the DNS provider your domain is using (it can be either a specific DNS provider or your current registrar) offers you to create subdomains and if they allow multiple levels.

If not, you can switch to a DNS hosting service that offers you more advanced DNS features. Keep in mind that you don't necessarily need to change web hosting or registrar, you can easily point the name server to another DNS provider without transferring the domain.

  • Thanks. I have GoDaddy as the registrar, so I'll test. I'll accept your answer when SE allows -- says I have to wait 8 mins, lol.
    – user35138
    Jan 12, 2014 at 12:55
  • @JeremyMiller: It's probable that GoDaddy automatically created the www.eg.example.com A record in DNS at the time you created the eg subdomain.
    – MrWhite
    Jan 12, 2014 at 15:55

I think you need a redirect in your .htaccess file (assuming you are using Apache server) to redirect from www.eg.example.com to eg.example.com

Use a 301 redirect. It will look like this:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\. [nocase]
RewriteRule .* http://eg.example.com%{REQUEST_URI}%{QUERY_STRING} [redirect=301,L]

The first line turns on the next following rewrite lines. The second line tests for host names that begin with 'www.' (and is case insensitive), e.g. will find both 'www' and 'WWW' and 'Www' The third line is the business line. If line 2 tests true, line 3 executes. It rewrites the URL that your user sent. It issues a redirect 301, which is permanent. And it exits, because of the 'L'. It also keeps any path and query intact (assuming that is what you want). The user's browser gets this redirect, as well as Google, DuckDuckGo, etc. And the user will see the line they typed changed into the correct URL.


Here is the solution:

open page on your domain folder



if ( preg_match( '|^([a-zA-Z0-9-])+$|', $blog['domain'] ) )


if ( preg_match( '|^([a-zA-Z0-9.-])+$|', $blog['domain'] ) )

Every domain will be acessible by

http://www.example.com and http://example.com


http://www.subdomain.example.com and http://subdomain.example.com

Including any subdomain, to solve this problem you just need do a 301 redirect to force your visitors to acess only. This will be good for your SEO and google ranking because your page rank is shared by prefix www. and non-www

For example: 10 strongly ranked sites links the page: www.example.com/page.html 5 strongly ranked sites links the page: example.com/page.html

Your pagerank points will be shared to 2 "differents" websites

How to solve, the best simple way:

Create a .htacess (or edit if you already have)

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\. [nocase]
RewriteRule .* http://eg.example.com%{REQUEST_URI}%{QUERY_STRING} [redirect=301,L]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.