Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have the following .htaccess file (usual one for MediaWiki):

RewriteEngine On
RewriteRule ^wiki/(.*)$ /w/index.php?title=$1 [PT,L,QSA]
RewriteRule ^wiki/*$ /w/index.php [L,QSA]
RewriteRule ^/*$ /w/index.php [L,QSA]

And I want to restrict access to some paths (e.g. ^wiki/Private/(.*)$) with the password.

Is there any possibility to do that using .htaccess? There is no /wiki/ directory, so it isn't possible to put .htpasswd inside it.

Thank you.

share|improve this question
up vote 1 down vote accepted

You would typically do this using <Location> directives, but these can only be specified in your server configuration (i.e., not in .htaccess files). Is there a particular reason you're trying to do this with a .htaccess file?

For example:

RewriteEngine On
RewriteRule ^wiki/(.*)$ /w/index.php?title=$1 [PT,L,QSA]
RewriteRule ^wiki/*$ /w/index.php [L,QSA]
RewriteRule ^/*$ /w/index.php [L,QSA]

<Location /wiki/Private/>
    # put your auth configuration here
share|improve this answer
Yes, it isn't my own server but web hosting. – Nikolay Vyahhi Nov 23 '10 at 20:38

you could use something like:

<AuthnProviderAlias file yourfile-htpasswd>
        AuthUserFile    /somedir/htpasswd

in a server configuration file to assign an alias for an authentication provider. then, something like:

AuthBasicProvider yourfile-htpasswd
AuthName "Temporary Login"
AuthType Basic
require valid-user

in a .htaccess file (in Private) should work.


share|improve this answer
OP indicated that the filesystem does not correspond to the URL structure so there is no "Private" directory into which one would put a .htaccess file. – larsks Nov 23 '10 at 14:54
hm, point taken - if there is no wiki, no Private, no other real directory at all then there is no .htaccess file covering the case. – iiegn Nov 23 '10 at 15:04
That's why the question was asked ;) There's no real directory — only path alias which I want to make private. – Nikolay Vyahhi Nov 23 '10 at 20:41

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.