多领域的htaccess登陆领域、htaccess

2023-09-02 00:58:59 作者:莫欺少年一时穷

我有一个多域名网站(定制CMS),所有网站都有相同的DocumentRoot。根据不同的网址(域名),这将成为一个不同的网站。由于只有1根,他们也只有1的.htaccess

I've got a multi domain site (custom CMS) where all sites have the same documentroot. Depending on the url(domain) it will serve a different site. Having only 1 root they also have only 1 .htaccess

现在我要保护1域用一个简单的.htacess登录(这样)

Now I want to protect 1 domain with a simple .htacess login (like this)

如何指定此登录到1域?

How do I specify this login to 1 domain?

推荐答案

您可以使用的 mod_setenvif 支持保护只有一个你的域。下面是你需要把你的共同的.htaccess $ DOCUMENT_ROOT 的code:

You can use mod_setenvif support to protect only one of your domain. Here is the code that you need to put in your common .htaccess under $DOCUMENT_ROOT:

SetEnvIfNoCase Host ^www.subdomain.com$ SECURED=yes

AuthType Basic
AuthName "My Protected Area"
AuthUserFile /your/path/to/passwords
Require valid-user
Satisfy         any
Order           allow,deny
Allow from      all
Deny from       env=SECURED

以上code将只显示 www.subdomain.com 基本身份验证弹出,同时使其他领域的开放。

Above code will show basic auth popup only for www.subdomain.com while leaving other domains open.