6

I have a main domain being hosted through CPanel. I also have a sub-domain that I would like to appear as a path under the main domain instead of as a sub-domain. So I have:

http://example.com/ pointing to the main hosted file.
http://example.com/mydir pointing to the subdomain files.

This is achieved by a httpd.conf include from the main domain section to set an alias:

alias /mydir /path/to/subdomain/files/

Now, that works fine so far.

The problem is that if a .htaccess file under /path/to/the/subdomain/files/ contains an error, the alias is completely skipped, and /mydir goes instead to the main host files. That is kind of surprising to me - I would expect an error to return an error instead.

Now the killer: if I try to password protect /path/to/subdomain/files/, then trying to access http://example.com/mydir will again attempt to deliver from under the main hosted files and not from /path/to/subdomain/files/.

I am not seeing any errors reported on the .htaccess file in the apache error log, so I am assuming the .htaccess is valid:

AuthUserFile /path/to/valid/readable/.htpasswd
AuthName "Secure Access"
AuthType Basic
Require valid-user

This kind of behavior does not seem right to me. Is there something obvious that could be causing it? Or is this just the way it works? Perhaps using an alias is the wrong way to go?

6
  • The reason for keeping the files in /mydir in a separate area (in a CPanel subdmain for convenince) is for organisation of the scripts. The reason for using an alias folder under the one domain is so they can share a certificate.
    – Jason
    Commented Sep 2, 2012 at 23:33
  • If I comment out Require valid-user from my .htaccess, then I see the files from /path/to/subdomain/files and if I uncomment Require valid-user then I see the main domain files (a Drupal CMS). How can requiring a valid user cause apache to deliver files from completely different directories?
    – Jason
    Commented Sep 3, 2012 at 0:09
  • Could I be missing an authentication module in httpd.conf? None seem to be set.
    – Jason
    Commented Sep 3, 2012 at 1:20
  • alias /mydir /path/to/subdomain/files/ try making it alias /mydir/ /path/to/subdomain/files/ with a trailing slash after the alias.
    – ionFish
    Commented Sep 3, 2012 at 2:28
  • I've tried that, with no change. With Require valid-user set I see one directory (the wrong directory) and if I comment it out I see the right directory. In either case there is no user/password prompt and nothing in the apache error log.
    – Jason
    Commented Sep 3, 2012 at 8:34

1 Answer 1

1

Do you have to use .htaccess for authentication?

I know you can simulate this in PHP with $_SERVER['PHP_AUTH_USER'] (documentation here). This would only work for PHP, but other languages probably support this kind of thing.

Your Answer

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

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