Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8779715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:52:02+00:00 2026-06-13T19:52:02+00:00

I have a .htaccess file for a directory on my apache server. Currently this

  • 0

I have a .htaccess file for a directory on my apache server. Currently this makes use of mod_auth_mysql for user verification to view the directory listing. However, if the user is already logged in to my application (therefore a cookie exists), I want to skip the valid user requirement and therefore eliminate multiple logins.

Current .htaccess

AuthName "Please don't hack the server, cheers"
AuthBasicAuthoritative Off
AuthUserFile /dev/null
AuthMySQL On
AuthType Basic
Auth_MYSQL on
Auth_MySQL_Host localhost
Auth_MySQL_User username
Auth_MySQL_Password password
AuthMySQL_DB auth
AuthMySQL_Password_Table users
Auth_MySQL_Username_Field username
Auth_MySQL_Password_Field password
Auth_MySQL_Empty_Passwords Off
Auth_MySQL_Encryption_Types Plaintext
Auth_MySQL_Authoritative On
require user james

The Cookie Check

RewriteEngine On
RewriteCond %{HTTP_COOKIE} !^cookiename=ok$
RewriteRule .* / [NC,L]

How do I combine these two correctly, to first check for the cookie and allow through if found, and then check for a valid user if the cookie is not found?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T19:52:03+00:00Added an answer on June 13, 2026 at 7:52 pm

    You need to do 2 things here, you can create an environment variable using the SetEnvIf directive and check it against Cookie. Then you need to tell mod_auth_mysql to allow any set of requirements to satisfy the authentication.

    First the environment variable:

    SetEnvIf Cookie cookiename=ok norequire_auth=yes
    

    The cookiename=ok is a regular expression that matches against the Cookie: HTTP header. Then the Satisfy:

    Order Deny,Allow
    Satisfy Any
    
    # your auth stuff:
    AuthName "Please don't hack the server, cheers"
    AuthBasicAuthoritative Off
    AuthUserFile /dev/null
    AuthMySQL On
    AuthType Basic
    Auth_MYSQL on
    Auth_MySQL_Host localhost
    Auth_MySQL_User username
    Auth_MySQL_Password password
    AuthMySQL_DB auth
    AuthMySQL_Password_Table users
    Auth_MySQL_Username_Field username
    Auth_MySQL_Password_Field password
    Auth_MySQL_Empty_Passwords Off
    Auth_MySQL_Encryption_Types Plaintext
    Auth_MySQL_Authoritative On
    require user james
    
    Allow from env=norequire_auth
    

    So the Satisfy Any means we allow if require user james is satisfied or if Allow from env=norequire_auth is satisfied. Without the satisfy, both lines would need to be satisfied in order to allow access.

    Note that cookies can easily be forged and this system isn’t a good way to protect your pages. You’d at least need to check the cookie’s value for a session ID or something.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a .htaccess file set up with this rule: RewriteRule ^([a-zA-Z0-9_-]+)$ user\.php?user=$1
I have the following .htaccess file in a directory: RewriteEngine On RewriteCond %{HTTPS} !=on
In my root directory I have a htaccess file which is caching all sort
I have this .htaccess file in WordPress. It's located at /public_html/ (web root). I
Say I have a htaccess file shared by dev.server and server.site.com. The first domain
Ok, so I have this .htaccess file that contains this <IfModule mod_rewrite.c> RewriteEngine On
I have a server. (Apache). On this server there is a subdirectory (subdir1). In
I have the following .htaccess on an Apache/2.4.2-win32 server: # Turn mod_rewrite on RewriteEngine
I have a .htaccess file that looks like this: SetEnv APPLICATION_ENV development RewriteEngine On
My web server is Apache. I have disabled directory listings via an Options -Indexes

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.