How do I use .htaccess with offline html?

0

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:

<Files ~ "^\.(htaccess|htpasswd)$">
deny from all
</Files>
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)

TaylorS

Posted 2019-05-24T12:31:43.583

Reputation: 121

Related question by same OP on Stack Overflow. – slhck – 2019-05-24T13:01:43.160

@slhck How does that relate to this question, the original question was about running a website with a port forward, this was about running an offline site with features of htaccess.. – TaylorS – 2019-05-24T17:19:12.460

Quite obviously, it's about the same underlying problem (also hinted at by your comment about port forwarding below my answer). Having the full context helps others answer your question; it's always better to give the full picture when asking. See also: http://xyproblem.info/ — you're never going to get a sufficient answer if you ask about fragments of your original problem.

– slhck – 2019-05-25T10:24:53.483

Answers

2

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.

slhck

Posted 2019-05-24T12:31:43.583

Reputation: 182 472

Is there a way to turn my pc into a webserver? ive tried many methods, but they are non-user-friendly and tend to not work, port forwarding is out of the picture, my dad would freik out of he saw his router sending out a ton of website data and crap. – TaylorS – 2019-05-24T12:39:41.450

Ive seen even simple iOS apps that send out server data, and allow me to connect to localhost:8000 but I cant seem to get that to work on pc, and send my data into it – TaylorS – 2019-05-24T12:40:39.463

1I think you're mixing up a few concepts here. Please go back a few steps, take a few minutes to edit your question, and tell us what you are actually trying to accomplish with that website, where it should run, what functionality it should have, from where it should be accessible etc. – slhck – 2019-05-24T12:42:26.593

thankyou for the answer, I believe I understand it a bit more, in my eyes, I believe what you mean, is to use apache as a form of webserver, in which I can port my directory of choice into an online URL (Usually my computer's IP Address) Im still struggling to understand how to USE apache, but I think one day I will understand. – TaylorS – 2019-05-28T12:07:08.917

Yes, that is basically what Apache will do. Once you install it, you have to configure it to serve some directory of your choice at its default IP adddress. Usually that is /var/www/, see https://stackoverflow.com/questions/5891802/how-do-i-change-the-root-directory-of-an-apache-server

– slhck – 2019-05-28T13:13:33.887