Page 1 of 1

.htpasswd problems

Posted: Mon Jun 08, 2009 6:24 am
by meraj
Hello all,

I did a search to see if a solution had been posted to this problem before, and this very similar to the problem I'm experiencing:

http://forum.cmsmadesimple.org/index.ph ... 386.0.html

I have CMSMS installed in the web root, and my .htaccess file contains this:

Code: Select all

Options +FollowSymLinks
RewriteEngine on
RewriteBase /

# 301 Redirect all requests that don't contain a dot or trailing
# slash to include a trailing slash
RewriteCond %{REQUEST_URI} !/$
RewriteCond %{REQUEST_URI} !\.
RewriteRule ^(.*) %{REQUEST_URI}/ [R=301,L]

# Rewrites urls in the form of /parent/child/
# but only rewrites if the requested URL is not a file or directory
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteRule ^(.+)$ index.php?page=$1 [QSA]
So I am using pretty URLs which work perfectly. But my problem now is that when I try and create a new password protected directory (like /secret for example), trying to access it via the browser returns a 404 instead of prompting for a username and pawword as I was expecting. If i remove the .htaccess file, the password pretection works as expected. I did a little debugging and figured out that it's the last three lines of the .htaccess file that are causing this problem, and unfortunately those are necessary for the pretty URLs to work.

I searched quite a bit and never quite found a simple fix for this that I could understand. Has anyone experienced this problem, and does anyone have any solutions or suggestions? Thanks in advance.

-m

Re: .htpasswd problems

Posted: Mon Jun 08, 2009 7:42 am
by Jeff
I am not the best with .htaccess rewrite rules but try adding these lines to the file at line 4.

Code: Select all

RewriteCond %{REQUEST_URI} ^/(secret/|missing\.html|failed_auth\.html) [NC]
RewriteRule . - [L]
replace "secret" to the name of the directory.

Re: .htpasswd problems

Posted: Mon Jun 08, 2009 7:52 am
by meraj
ajprog wrote: I am not the best with .htaccess rewrite rules but try adding these lines to the file at line 4.

Code: Select all

RewriteCond %{REQUEST_URI} ^/(secret/|missing\.html|failed_auth\.html) [NC]
RewriteRule . - [L]
replace "secret" to the name of the directory.
thank you for your response. i just gave a try to the above suggestion and unfortunately it did not fix the issue. but i appreciate the attempt! :)

i dont know if it's relevant, but i have custom 404 pages enabled in CMSMS.

-m

Re: .htpasswd problems

Posted: Mon Jun 08, 2009 8:00 am
by Jeff
I went to verify in my .htaccess file this is what I have at the begin of the file so I can go to my stats page.

Code: Select all

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/(stats|failed_auth\.html).*$ [NC]
RewriteRule . - [L]
</IfModule>

Re: .htpasswd problems

Posted: Mon Jun 08, 2009 8:13 am
by meraj
ajprog wrote: I went to verify in my .htaccess file this is what I have at the begin of the file so I can go to my stats page.

Code: Select all

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/(stats|failed_auth\.html).*$ [NC]
RewriteRule . - [L]
</IfModule>
Hmm no, still no luck :( It's so frustratingly simple, yet elusive. Any .htaccess wizards have any wisdom to dispense?  :-\

-m

Re: .htpasswd problems

Posted: Thu Jul 08, 2010 11:36 pm
by Gamonon
Quite an old post but for me still a problem.

I brought this problem back tot the RewriteRule. If the RewriteRule is removed from the .htaccess file in the root, the .htaccess and .htpasswd work fine for the protected directory.

If the RewriteRule is in place, the files in the protected directory are not found and a 404 is shown.

The RewriteRule is necessary for the Pretty url to work so I can't leave it out.

Does someone has a clue how to solve this?

Thanks