简体   繁体   中英

how to make the .htaccess rule work for specified domain ,subdomain or addons

This is my cpanel directory structure:

public_html
    |--->wordpress installed 

sudomain-directory
    |--->wordpress installed
addon-domain
    |--->wordpress installed

What I have done: Based on user choice the passwd and .htaccess file will be created to respective domains inside wp-admin directory

.htaccess file

authname "member only"
authtype basic
authuserfile /home/taragurung/public_html/wp-admin/.passfile
require valid-user

Now when user try to access www.somedomain.com/wp-admin the authentication will pop up and it works as expected.

Problem: The problem is it works only for wp-admin but not for the www.somedomain.com/wp-login

To make it work I added the <FilesMatch "wp-login.php"> rule and created the .htaccess in the root directory

but doing so will make the rule apply to all the domains and subdomains

Why I didn't put it in root directory: I don't want the rules to be implemented on all the subdomains and addon domains. Want it to be implemented on only those domains or sub-domain user choose to.

I hope I've understood your question correctly - but you only want the authentication to work if the user directs from a specific domain.

To do this you can use an if directive .

So, if user x comes from the domain somedomain.com/wp-login then it will show the authentication, if they do not, then it will not show it.

<if "%{HTTP_HOST} == 'somedomain.com/wp-login'">
    authname "member only"
    authtype basic
    authuserfile /home/taragurung/public_html/wp-admin/.passfile
    require valid-user
</if>

I hope this helps and as always, clear your cache before testing this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM