1

I am currently trying to combine the two - htaccess password protection and mod_rewrite. My problem is, that the code below is resulting an error: "No input file specified."

<IfModule mod_rewrite.c>
    Options +FollowSymLinks -MultiViews

    DirectoryIndex index.php

    AuthType Basic
    AuthName "Password Protected Area"
    AuthUserFile .htpasswd
    Require valid-user

    RewriteEngine on

    RewriteCond %{HTTP_HOST} !^www\.
    RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

    RewriteRule ^$    public/    [L]
    RewriteRule (.*) public/$1    [L]
 </IfModule>

Can anyone see, what I am doing wrong?

EDIT #1:

<IfModule mod_rewrite.c>
    Options +FollowSymLinks -MultiViews

    DirectoryIndex index.php

    AuthType Basic
    AuthName "Password Protected Area"
    AuthUserFile /.htpasswd
    Require valid-user

    RewriteEngine on

    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]

    RewriteRule ^((?!public/).*)$ public/$1 [L,NC]
 </IfModule>
denlau
  • 916
  • 2
  • 9
  • 21

1 Answers1

0

Make sure AuthUserFile has full path to a valid encrypted passwords file.

Rest of the code, have it like this:

<IfModule mod_rewrite.c>
    Options +FollowSymLinks -MultiViews

    DirectoryIndex index.php

    AuthType Basic
    AuthName "Password Protected Area"
    AuthUserFile /full/path/to/.htpasswd
    Require valid-user

    RewriteEngine on

    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]

    RewriteRule ^((?!public/).*)$ /public/$1 [L,NC]
 </IfModule>
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • That still results in "No input file specified".. Is that because I haven't typed a correct path for the .htpasswd? :) – denlau Oct 15 '13 at 18:22
  • Yes it can very well be, check your apache's error.log for exact error. What URL are you using to test it? – anubhava Oct 15 '13 at 18:27
  • I have added my current file as an edit to my question. How do I check the error.log? I am currently on a host, that I've paid for, so not sure that I can actually access the log? :) – denlau Oct 15 '13 at 18:36
  • `AuthUserFile /.htpasswd` is invalid. If you have passwd file in DOCUMENT_ROOT then you can use `AuthUserFile ${DOCUMENT_ROOT}/.htpasswd` – anubhava Oct 15 '13 at 18:46
  • Hmm, I am having BOTH my .htaccess and .htpasswd in the root? And the suggestion above does still give the "input file not specified" :) – denlau Oct 15 '13 at 18:51
  • I'll try it.. Yes, I have made my own PHP-framework, which handles all the routing according to the $_GET['url'] :) – denlau Oct 15 '13 at 19:00
  • Hmm, no, it didn't :) – denlau Oct 28 '13 at 16:58
  • That was wonderfully helpful comment. You're responding after 2 weeks and this cryptic comment which doesn't give any details on what exactly is not working for you. – anubhava Oct 28 '13 at 17:06
  • Anubhava: I haven't got the code with me at the moment.. I'll give you some more info later tonight. Sorry. :-) – denlau Oct 28 '13 at 17:21