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.

  • DocumentRoot is htdocs/sd - if you expect /sd/ answers with 404, why do you set it as DocumentRoot? – Evgeniy Aug 26 '19 at 11:13
  • DocumentRoot for the subdomain is htdocs/sd. I expect a 404 for sd.example.com/sd, because this would point to htdocs/sd/sd. Or am I misunderstanding something here? – kraligor Aug 26 '19 at 11:34
  • 1
    Gee...let me guess, Are you using cPanel? Your basic Apache configuration is incorrect. cPanel is known for this. Let me know and I will look for an answer I made years ago with a good configuration example for you to follow. Cheers!! – closetnoc Sep 30 '19 at 22:48

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.

| improve this answer | |

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/
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.