hoozh.net

cole hoosier’s blog

About

Here you'll find updates on big events in my life as well as photos, a calendar, and my resume.

I spent a good portion of the last two days trying to get iCal to publish calendars to my PHPiCalendar installation using publish.ical.php. Whenever I tried to add auth in my /calendar/calendars/.htaccess with something like this I’d get a 404 error displayed by wordpress:

AuthType Basic
AuthName "iCal Upload"
AuthUserFile "/home/username/.htpasswds/calendar/calendars/passwd"
require valid-user

The relevant code in my /.htaccess file was:

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

I couldn’t figure out what was going on until I stumbled across this page after several hours of Googling. It seems that when the server sent back a 401 response (unauthorized), it was also trying to send out a page explaining the error. The RewriteRule in my root’s .htaccess sucked up that error page’s URL and displayed my blog instead. I’m not entirely sure why this happened. It seems like I still should have gotten a 401 response in my browser and tried to supply a username/password then, but that’s not how it worked.

Here are the contents of the two .htaccess files once I got it working.

/.htaccess:

Options +FollowSymlinks

RewriteEngine on
RewriteBase /


# otherwise the 401 page gets handled by WP
ErrorDocument 401 /unauthorized.html

# BEGIN WordPress

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

# END WordPress

/calendar/calendars/.htaccess:

Options +FollowSymlinks


RewriteEngine on

RewriteCond %{REQUEST_METHOD}  ^PUT$ [OR]
RewriteCond %{REQUEST_METHOD}  ^PROPFIND$ [OR]
RewriteCond %{REQUEST_METHOD}  ^DELETE$
RewriteRule ^.*$ publish.ical.php [L]


AuthType Basic
AuthName “iCal Upload”
AuthUserFile “/home/hoozh/.htpasswds/calendar/calendars/passwd”
require valid-user

Hopefully this will help someone solve the same problem I was having sooner!

One Response to “mod_rewrite and http auth with .htaccess”

  1. I’ve been banging my head against the wall on this one for hours… Thanks!

    Chris Murphy

Leave a Reply