Editing dynamic content with WebDAV

Jul 29, '03 10:15:00AM

Contributed by: jabest

One of the problems with using WebDAV is that you can't open (GET) files that have any kind of server-side rendering, like PHP files. When you open these files, if you can open them over WebDAV at all, you're treated to the rendered page. That sucks!

Here's where mod_rewrite comes in. Apache comes with a very powerful rewriting engine, which allows you to change the content of just about everything on the fly. We can use this power to turn our dynamic pages into something static to suit our editing needs.

Chances are your WebDAV directory configuration in httpd.conf looks something like this:


<Directory /Library/WebServer/Documents/dav>
    DAV On
    AllowOverride AuthConfig
    Options FollowSymLinks Indexes
    AuthName "WebDAV Restricted"
    AuthType Basic
    Require valid-user file-owner file-group
</Directory>
Read the rest of the hint for the changes to implement mod_rewrite...

Now then, if we add the following two lines, in this case, to be able to edit PHP pages, we're in business:


    RewriteEngine on
    RewriteRule     (.*).php$ - [T=text/plain,L]
For the final product below:

<Directory /Library/WebServer/Documents>
    DAV On
    AllowOverride AuthConfig
    Options FollowSymLinks Indexes
    AuthName "WebDAV Restricted"
    AuthType Basic
    Require valid-user file-owner file-group
    RewriteEngine on
    RewriteRule     (.*).php$ - [T=text/plain,L]
</Directory>
So what's going on here? The first line tells Apache to turn on the Rewrite engine. Simple enough. In the second line, we're saying "All URLs that end with .php (the regular expression), do not rewrite the URL (the hyphen), but change the MIME-type to text/plain (the T=text/plain), and make this the last rewrite rule, so that we don't get stuck in a recursive loop (the L)".

There are other ways of accomplishing the same thing, but this is the one that worked for me. It should also work with any other file type. I tried it out for .html and .htm as well, just by changing the regular expression. Worked fine.

Only one caveat. This doesn't seem to work with Digest authentication or SSL (not even when connecting with a PC). I'm not sure why, but if I figure it out, I'll send another post.

Comments (11)


Mac OS X Hints
http://hints.macworld.com/article.php?story=2003072620172473