I have a site that serves up certain content based on the subdomain. So it is the same set of files, and maybe the header and some info in the site pages changes based on the subdomain.
I need to have different htpassword authentication based on the subdomain as well, but can't find info on how to do an if/then type of thing in htaccess .
Basically what I need is this:
if subdomain = 'abc' use this htpassword file
if subdomain = 'def' use this htpassword file
Can this be done?
htaccess rewrite rules can be used to direct requests for one subdirectory to a different location, such as an alternative subdirectory or even the domain root. In this example, requests to http://mydomain.com/folder1/ will be automatically redirected to http://mydomain.com/folder2/.
htaccess rewrite rule includes setting a combination of rewrite condition ( RewriteCond ) tests along with a corresponding rule ( RewriteRule ) if the prior conditions pass. In most cases, these rules should be placed at any point after the RewriteEngine on line in the . htaccess file located in the website's docroot.
You can have more than one . htaccess file on your hosting account, but each directory or folder can only have one. For example, you can have separate . htaccess files in your root folder and another in a sub-folder.
There are two main directive of this module: RewriteCond & RewriteRule . RewriteRule is used to rewrite the url as the name signifies if all the conditions defined in RewriteCond are matching. One or more RewriteCond can precede a RewriteRule directive.
Try something like this:
SetEnvIf Host ^abc\. HOST_ABC
SetEnvIf Host ^dev\. HOST_DEF
<IfDefine HOST_ABC>
AuthUserFile …
</IfDefine>
<IfDefine HOST_DEF>
AuthUserFile …
</IfDefine>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With