Tuesday, November 18, 2014

google chrome - How do I use .htaccess with offline html?


I have an offline webpage composed of Html, CSS, and JS, it runs completely offline. One problem, I want to use htaccess to add Username/Passwords to my webpage, along with other features of htaccess, like Removing url page extensions (site/page1.html > site/page1) and things like error 404 Pages and such, but when I connected my htaccess and htpasswd to my main site html file and my webpage, nothing happened when I opened the site, no password requests, no 404 pages on fake urls, no hidden file extensions. Does it only work with online sites?


In basic terms, I want to run Mainsite.html on a PRIVATE DOMAIN (just a file address or an IP (I cant really port forward so this is difficult)) and then be able to use htaccess features.


Main site name: Mainsite.html


htaccess code:



deny from all

Options Indexes
AuthUserFile .htpasswd
AuthGroupFile /dev/null
AuthName "Please enter your ID and password"
AuthType Basic
require valid-user
DirectoryIndex MainSite.html
order deny,allow
htpasswd code:
userAdmin:-----------
(I cant even show encrypted pass for reasons)

Answer



Features like password-protected access (e.g. via .htaccess) and URL rewriting (e.g. stripping out .html from the path) require a web server. I assume that this is what you mean by “online”.


You need to set up a web server that serves your files via the network, rather than just opening the HTML files from your PC directly from a browser. So, rather than opening C:/some_file.html in the browser, you'd open, for example, http://127.0.0.1:8080/some_file, which would make a request to a web server that is running on your machine, on port 8080, which then sends the HTML content of that file to your browser.


Apache would be an obvious solution; it's the one that's used most often, and it has the features you are looking for. You'll find plenty of documentation on how to install Apache on your system and get it to serve a set of files in some directory.


It seems to me you should read some tutorials on building and hosting web sites.


No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...