Search code examples
html.htaccesscachingbasic-authentication.htpasswd

How to Cache a .htaccess & .htpasswd/Authorization Required Offline


I have a working website with a verification/login using .htaccess & .htpasswd. When trying to cache it I get the error:

Application Cache Error event: Resource fetch failed (403) http://fman.cf/.htaccess

I'm not sure if their is another way to have an offline verification but here is my Offline.appcache file:

CACHE MANIFEST
# Cache Manifest Version: 1.0
# For Offline Usage
# Reminder: JQuery

CACHE

/Javascript.js
/Styles.css
/RPS.jpg
/RPS.html
/Miji.html
/Murderer.jpeg
/Lottery.png
/403.html
/404.html
/.htaccess
/.htpasswd
/.quarantine/*
/.tmb/*

NETWORK

*

FALLBACK

/404.html

# Last Update:
# 6/2/2015

.htaccess:

# DO NOT REMOVE THIS LINE AND THE LINES BELOW ERRORPAGEID:asdfasdf
ErrorDocument 403 /403.html
# DO NOT REMOVE THIS LINE AND THE LINES ABOVE asdfasdf:ERRORPAGEID


# DO NOT REMOVE THIS LINE AND THE LINES BELOW ERRORPAGEID:adsfasdf
ErrorDocument 404 /404.html
# DO NOT REMOVE THIS LINE AND THE LINES ABOVE asdfasdf:ERRORPAGEID


AddType text/cache-manifest .appcache







# DO NOT REMOVE THIS LINE AND THE LINES BELOW PWPROTECTID:passblahblah
AuthType Basic
AuthName "Restricted Access"
AuthUserFile /home/myid/public_html//.htpasswd
Require user admin
# DO NOT REMOVE THIS LINE AND THE LINES ABOVE blablah:PWPROTECTID

.htpasswd:

USERNAME:MY_PASSWORD

NOTE: All of the comments in the .htaccess were placed their by my hosting service, I did change all the actualy numbers/words/passwords to random stuff.


Solution

  • .htaccess files are not available offline, because the server (Apache) uses them, not the browser. This is an important point which I think you did not understand yet. The server looks into the file and uses it to offer login, the login itself does not happen in the .htaccess file. A standalone .htaccess file doesn't do anything, it only contains text.

    Files starting with .ht are blocked to the public by default Apache configuration.

    There is no way you can implement an offline login using HTML.

    The .htaccess can be cached serverside in two ways:

    1. Move the configuration to a standalone apache configuration permanently loaded (instead of dynamically loaded .htaccess).

    2. Put the .htaccess file on a ramdisk.

    None of those methods would speed up anything significantly, nor would it allow the user to login offline.