1

I have a strange problem with a site I'm working on, it really drives me crazy, although it should just be working.

I have a site at domain.nl, and a CMS at domain.nl/cms. All request except images, css etc and the /cms folder, are redirected to domain.nl/mesam/mesam.php, with a .htaccess file in the root.

In the /cms folder, there is a basic http auth, with a .htaccess and .htpasswd in that folder.

domain.nl is working good, except domain.nl/cms is redirected to mesam/mesam.php, making the /cms folder unreachable.

Now, two ways to get the cms reachable: 1) I remove the .htacces in the root folder, breaking the whole site (except /cms) 2) I remove /cms/.htaccess, the site itself keeps working, domain.nl/cms results in an unsecured CMS, which I of course do not want.

Here some contents:

domain.nl/.htaccess:

RewriteEngine On    
RewriteCond %{REQUEST_URI}  !^/cms
RewriteCond %{REQUEST_URI}  !(\.png|\.jpg|\.gif|\.jpeg|\.bmp|\.css|\.js|favicon\.ico|\.svg|\.pdf|\.ino)$ [NC]    
RewriteRule (.*)  mesam/mesam.php [L]

domain.nl/cms/.htaccess:

AuthName "CMS"
AuthUserFile <<www_root>>/cms/.htpasswd
AuthGroupFile /dev/null
AuthType Basic
require valid-user

The strange thing is, this exactly same setup works for another site (domain2.nl) at the same server, the same directory structure and the same htaccess-contents. Google proved helpfull, in the way that it told me that the setup I use is correct (as proven by domain2.nl).

I really hope there is someone who can help me out. I'm running PHP7 on Apache, on a shared hosting server with CPanel (and some Linux distro running). The PHP and server settings for domain.nl and domain2.nl are the same.

DavidKunz
  • 325
  • 3
  • 8

1 Answers1

0

Try this solution:

Add ErrorDocument 401 "Authorisation Required" after authorisation section.

You have replace

AuthName "CMS"
AuthUserFile <<www_root>>/cms/.htpasswd
AuthGroupFile /dev/null
AuthType Basic
require valid-user

with

AuthName "CMS"
AuthUserFile <<www_root>>/cms/.htpasswd
AuthGroupFile /dev/null
AuthType Basic
require valid-user
ErrorDocument 401 "Authorisation Required"

Reference: Solving 404 Errors When Using Htpasswd

David Buck
  • 3,752
  • 35
  • 31
  • 35