Skip to main content

Basic Auth .htaccess but allow specific URL to pass through

Comments

5 comments

  • cPanelLauren
    To clarify, these are customers logged in to the wordpress backend correct? I'd think that the only way to prevent that password protection from popping up would be to redirect the user elsewhere on logout. Redirecting them to wp-login on logout would prompt the password auth otherwise any time an unauthenticated user lands on that page they will be prompted. The following might be helpful:
    0
  • WorkinOnIt
    Hi @cPanelLauren thanks for your reply and suggestion.
    To clarify, these are customers logged in to the wordpress backend correct?

    Technically yes as they are logged in as WooCommerce shop customers - but without access to wp-admin.
    I'd think that the only way to prevent that password protection from popping up would be to redirect the user elsewhere on logout.

    That is an interesting idea. I have experimented with various options, however it seems in order to logout, the WordPress URL /wp-login.php&action=logout must be called - therefore always triggering the htaccess prompt. What would be the best way to redirect prior to that basic auth showing up?
    0
  • cPanelLauren
    Hi @WorkinOnIt Albeit I'm not an expert on this specific issue, but I think this can be done easiest in the functions.php for the theme: add_action('wp_logout','auto_redirect_after_logout'); function auto_redirect_after_logout(){ wp_redirect( site_url() ); exit(); }
    home_url
    or site_url
    can be replaced by an external URL as well.
    0
  • WorkinOnIt
    Hi @cPanelLauren Thanks for your suggestion - sadly it didn't work - because the wp-login.php launches before the redirect you've mentioned. So - how about taking a different track? Could it be possible to modify the .htaccess directive to precisely target the "wp-login.php" file, but ignore the longer quesrystring ( "wp-login.php?action=logout&redirect_to" ?? I tried the following but not working... suggestions? AuthName "Protected page" AuthType Basic AuthUserFile "/home/user/.pwrdfile" require valid-user Order Deny,Allow Deny from all #Allow from 192.168.64.5 # developers IP address Allow from wp-login.php&action=logout #<<<<<<<<<<< how to construct this ? Satisfy Any
    0
  • cPanelLauren
    Possibly? This is something that would be more geared towards a system administrator or developer though.
    0

Please sign in to leave a comment.