0

In /public_html/.htaccess, I've got rewrite rules as follows:

RewriteRule ^(subdir1)($|/) - [L]
RewriteRule ^(subdir2)($|/) - [L]

RewriteCond %{HTTP_HOST} ^(www.)?example.com$ [NC]
RewriteRule ^(.*)$ /www.example.com/$1 [L]

So, if a visitor goes to the url http://www.example.com/subdir1 (or subdir2), it will serve up the files from /public_html/subdir1 (or subdir2). Otherwise, it will 'default' to the files in /public_html/www.example.com. This works as intended.

However, if I place an .htaccess & associated .htpasswd file in /public_html/subdir1:

AuthType Basic
AuthName "Private"
AuthUserFile "/public_html/subdir1/.htpasswd"
require valid-user

...the RewriteRules suddenly break. Visiting http://www.example.com/subdir1 no longer serves up files from subdir1, instead returning a 404 from the CMS located in public_html/www.example.com/.

What gives? Why would adding a password to subdir break the parent's rewriterules?

  • Do you have anything else in /public_html/subdir1/.htaccess? – MrWhite Oct 21 '16 at 23:29
  • The path to your .htpasswd file would seem to be invalid? This should be an absolute file system path. – MrWhite Oct 22 '16 at 0:53
  • 1) Nothing else in .htaccess - just those four lines. 2) The path is absolute, & valid (the actual path I listed above was just an example - my htaccess actually lists /home/(my_username)/public_html/subdir1/.htpasswd. Apologies for being unclear, I was just abbreviating. – Metal450 Oct 25 '16 at 0:16
  • Check the error log and add any relevant entries to your post. Also how are you mapping request to your CMS, Via a rewrite, a ProxyPass, or is it just an app located in /public_html/www.example.com/ or something else? – Unbeliever Oct 30 '16 at 22:20
  • Since it's shared hosting, I unfortunately don't have access to the raw server error logs. The CMS is a Wordpress installation whose files are located in public_html/www.example.com. – Metal450 Nov 1 '16 at 21:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.