HTaccess file not working

This is what I have in my .htaccess file

RewriteEngine On
RewriteBase /
RewriteRule ^index.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]

AuthUserFile ./.htpasswd
AuthGroupFile /dev/null
AuthName “Please Enter Password”
AuthType Basic
Require valid-user

ErrorDocument 404 ‘errors/404.html’

AddType text/html .shtml
AddHandler server-parsed .shtml

XBitHack on
LogLevel alert rewrite:trace6

But when I Have that in the file, I get this error on the webpage

And without having that in the .htaccess file, it loads perfectly.
How Can i fix this, did I do my htaccess file wrong?

Hey @Callum-OKane, that syntax looks fine to me and checks out at http://www.htaccesscheck.com, so it may be something specific to your project’s configuration. If you can share your project name someone may be able to shed some light. Alternatively, you could remove sections one at a time to try to narrow down where the problem is yourself.

I have tried the removing sections idea, but it only works, when the .htaccess file is empty completely, The project name is Time-Desert, When I used the htaccess checker, i got this:


So its not that is it is correct.

Sorry if I miscommunicated; I meant to indicate that the problem probably isn’t with the htaccess syntax because it checks out fine.

I was able to test things by eliminating sections - because of the way Apache sites work in Glitch the project needs to restart for each change of the .htaccess file, so for every change you have to run refresh in the console, or otherwise restart the project.

My testing in a remix indicates that the AuthGroupFile directive is the one that’s causing the issue. In might be because you don’t have the groupfile module enabled, or perhaps it doesn’t like /dev/null as the value for that file - I didn’t troubleshoot that far. Eliminating that directive (and running refresh) allowed me to load the site in a remix of your project.

I am still getting Internal server error, And the apache seems to be working. But once I auth It gives error

Also, How can I make it so only a certain page needs to use the Auth

Ive also just realised, that when it gets an error, it does not show the contents of the 500.html file, it just says its directory

.htaccess files are not supported with Glitch, sadly.
You can, however do something like this:
image

After doing that, you can then go to the link, so it would be something like: example.glitch.me/some-random-stuff
image


It’s that easy.

Hey @Callum-OKane, I think you’ve got a few things going on:

  1. for both of your ErrorDocument declarations, those are relative to the root of your “site”, you you’ll want them to look like /errors/404.html
  2. the path to the AuthUserFile, on the other hand, should be absolute, so you’ll want something like AuthUserFile /app/.htpasswd
  3. I don’t know if you’re having trouble with getting a proper .htpasswd file set up, but I find the htpasswd command useful when doing that. If you’re getting errors but you think everything else is working, you might try discarding your .htpasswd file and generating a new one.
  4. To protect a single file you can use the Files directive and put the Require config inside it. So if you wanted to protect Status.html you’d use something like this:
# the general Auth config can be shared
AuthUserFile /app/.htpasswd
AuthName "test"
AuthType Basic

# then just require valid users for Status.html
<Files Status.html>
  Require valid-user
</Files>

Hope this helps!

@zira I am pretty sure they are supported, since it is working fine, its just me who is stupid. Also your way of just of doing the /home, does not work…

@cori I have gotten the error pages setup, I do not know how to use the htpasswd command, even though I have tried going with what it says do to, but still no success, I just want to be able to have it so I do not need the file extension in the url when accessing a page, so if you could help with that!

It should, if its a hello-webpage

And, they aren’t, I’ve read some things about .htaccess on Glitch already, they all say they’re not supported, and I’ve used a working .htaccess file, but it didn’t work

@zira, you are correct insofar as hello-webpage-based projects do not support .htaccess files. They use lws to serve the site and that doesn’t support htaccess syntax, although there are ways to accomplish the same sorts of things.

Since htaccess an Apache-specific feature, you have to be running Apache for it to work. Projects using a configuration like https://glitch.com/~lamp-poc run apache on startup and htaccess will work just fine in those projects.

@Callum-OKane I don’t know how I missed your follow up; my apologies.

htpasswd can be used to create a proper .htpasswd file for use in your .htaccess. Something like htpasswd -c /path/to/new/htpasswd username will create a new one and prompt for the password for the given username. then you can use /path/to/new/htpasswd in your .htaccess file and it should enable you to use Basic Auth, for example. The new htpasswd location has to not exist for that command to work, so if you wanted it at /app/.htpasswd you’d need to (re)move that file first.

As far as extensionless urls, I think you’re probably looking for something like what’s documented at https://alexcican.com/post/how-to-remove-php-html-htm-extensions-with-htaccess/.

Hope that helps!