Sub-domain vs sub-directory: what's the difference?

When your cPanel account is created it uses your primary domain e.g. example.co.uk

You'll notice there's nothing in front (e.g. www.) or behind (e.g. /blog) your domain name at this point.

Sub-domain - the part in front of the domain name

In cPanel, go to Domains and click Create A New Domain. Enter the subdomain you want - forum.example.co.uk, say - and untick "Share document root" so it gets a folder of its own rather than serving your main site. Our guide on adding a subdomain walks through it.

Subdomains are useful for anything you want kept separate from your main site - a forum, a staging copy, or software installed on its own.

Although www looks like a subdomain (and technically is) - this is often just a CNAME DNS record pointing at the domain.

Sub-directory - the part behind the domain name

You can create a folder inside any site's document root - the folder that site is served from - using the cPanel File Manager.

Your main website is served from a folder called public_html. Create a folder called blog inside it, put files there, and they appear at example.co.uk/blog.

But aren't subdomains just folders?

Nearly, but not quite - and the difference is where the folder lives.

A sub-directory goes inside public_html. Create public_html/blog and its contents appear at example.co.uk/blog, as part of your main site.

A subdomain gets a folder alongside public_html rather than inside it - so blog.example.co.uk is served from /home/yourusername/blog.example.co.uk. It is a separate place, and nothing in it is reachable from your main domain.

That means you can have both at once without them colliding: example.co.uk/blog and blog.example.co.uk are two different sites in two different folders.

A useful side effect. Because the subdomain's folder is outside public_html, it does not inherit your main site's .htaccess file. Redirects, rewrite rules and password protection you have set up for your main site will not apply to the subdomain - which is usually what you want for a staging copy, and occasionally a surprise if you were expecting them to carry over.


How did we do?

Powered by HelpDocs (opens in a new tab)
© Krystal Hosting Ltd 2002–