Mobile app version of vmapp.org
Login or Join
Ogunnowo487

: Password protect an alias virtual directory 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

@Ogunnowo487

Posted in: #Apache #Authentication #Cpanel #Htaccess #Htpasswd

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:
example.com/ pointing to the main hosted file. 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 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?

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Ogunnowo487

1 Comments

Sorted by latest first Latest Oldest Best

 

@Tiffany637

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.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme