Submit a enquiry






    Back to all posts

    .htaccess conditional based on URL

    Tip
    by Rocky Macnally Developer

    If you need to do a conditional in your .htaccess you can use something like the below (example based on getting a htpasswd file):

    <If "req('Host') == 'example.com'">
        AuthUserFile httpdocs/.htpasswd
        AuthType Basic
        AuthName "Password Protected"
        Require valid-user
    </If>
    <If "req('Host') == 'example2.com'">
        AuthUserFile httpdocs/.htpasswd
        AuthType Basic
        AuthName "Password Protected"
        Require valid-user
    </If>
    <Else>
        Require all granted
    </Else>

    If you have any trouble with your .htaccess please feel free to drop us a line and we would be happy to help.