પટેલ પરિવાર – The Patel Family

  • Home
  • About
  • Contact

WordPress permalinks and password protected sub directories

Published by Rahul on November 28, 2007 06:07 pm under Technology

Recently I changed the permalink structure on this blog. I updated the .htaccess file in the root directory with the following:

DirectoryIndex index.php

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteBase /index.php/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

After that change, suddenly all my password protected sub directories begin to return 404 errors. I tried playing around with different RewriteRules, RewriteCond to see if that would solve the problem, but nothing seemed to work.

Finally, I came across this post. It seems like Apache goes through the following stages when a password protected wordpress sub directory is requested:

  1. User requests www.exampleblog.com/subdir.
  2. subdir is password protected, so it sends back a 401 response to ask the user for a username/password.
  3. The .htaccess file sitting under the root directory processes the response. RewriteRules comes into play and rewrites the URL to www.exampleblog.com

How to resolve this problem?

  1. Create a dummy html file and put it under the root directory. The file doesn’t need to have any content. Let’s say the file is called onerror.html.
  2. Towards the top of the root directory’s .htaccess file, add this line:

    ErrorDocument 401 /onerror.html

Why does it work? Because once the subdir sends the 401 response, the ErrorDocument directive tells apache to serve the onerrror.html file to the client. The client however won’t display the file because it sees the 401 response in the header and asks the user for the username/password.

No comments yet

Posting your comment.

Leave a comment:

  • Categories

    • Budget
    • Gujarati
    • Poem
    • Quotes
    • Technology
    • Trivia
  • Recent Posts

    • Gujarati alphabet worksheet
    • એ તો કેવી અજબ જેવી વાત છે
    • Find in Files slow in Visual Studio 2003
    • Is your domain locked by VizaWeb? Want to get it unlocked?
    • આવ રે વરસાદ
  • Pages

    • About
    • Contact
    • Kids Poems – Gujarati (PDF)

Copyright © 2012 પટેલ પરિવાર – The Patel Family
WordPress Theme based on Light Theme