2

I've got a vhost set up for sd.example.com. DocumentRoot is htdocs/sd. Browsing to sd.example.com works as expected. But if I browse to sd.example.com/sd, I get the same result.

Is this expected behavior, and if so, how to disable it? I would have thought sd.example.com/sd would try to load htdocs/sd/sd, which should result in 404.

Happy to post my vhost confs if it isn't expected.

John Conde
  • 86,484
  • 28
  • 150
  • 244
kraligor
  • 121
  • 2

2 Answers2

1

First of all please make sure you did not accidentally copy 'sd' directly inside another 'sd', as this happens more often than one might think. Might be a good time to check if you have symlink back to the parent dir.

Also check if sd.example.com/asedfasdfasd returns an error or the same thing as sd.example.com

If possible please post your virtual host config, and can you confirm that sd.example.com/sd loads the page in that subdirectory or it redirects to sd.example.com

--I would write this as a comment but don't have enough rep to do so.

1

htdocs is usually usually the document root for your main domain example.com. I'm assuming that you mis-typed your example and that it is actually example.com/sd that gives you the same result as the subdomain. It is not advisable to create sub-directories of that to house sub-domains. Instead you should use a completely different document root. For example I create directories like this on my server for various document roots:

  • /var/www/example.com/
  • /var/www/sd.example.com/
  • /var/www/www.example.net/

That way none of the sub-domains are nested within another domain. Everything just works better.

Unfortunately on shared hosting, you may not have the luxury of managing your directory structure and document roots carefully. The shared hosting interface cPanel has a bad habit of hosting the main domain in a directory and creating sub-directories for sub-domains and add-on domains. In that case you have to put code in the .htaccess of the main domain to prevent sub-directory access.

Redirect permanent /sd/ http://sd.example.com/
Redirect permanent /sd http://sd.example.com/
Stephen Ostermiller
  • 99,822
  • 18
  • 143
  • 364