[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: How to access http://localhost/doc for FHS compliant packages



Andreas Tille <tillea@rki.de> writes:
> /etc/apache/srm.conf says:
> 
> Alias /doc/ /usr/doc/
> ## The above line is for Debian webstandard 3.0, which specifies that /doc
> ## refers to /usr/doc.  Some packages may not work otherwise. -- apacheconfig
> 
> OK, so far but now there are some packages which reside in /usr/doc
> and some in /usr/share/doc which both want to be accessed via
> http://localhost/doc.  What is the recommended way while we are in
> the process od switching to FHS.

Since this has come up a few times, here's a fairly complete solution:

In httpd.conf, enable mod_rewrite

    LoadModule rewrite_module /usr/lib/apache/1.3/mod_rewrite.so

if not already enabled.

In srm.conf, replace

    Alias /doc/ /usr/doc/

with

    <IfModule mod_rewrite.c>
    RewriteEngine on

    # For requested files beginning with /doc/, try looking for the
    # document in /usr/share/doc.
    RewriteCond       %{REQUEST_FILENAME} ^/doc/
    RewriteCond       /usr/share%{REQUEST_FILENAME} -f
    RewriteRule ^(.+) /usr/share$1 [L]

    # Next, try looking for the document in /usr/doc.
    RewriteCond       %{REQUEST_FILENAME} ^/doc/
    RewriteCond       /usr%{REQUEST_FILENAME} -f
    RewriteRule ^(.+) /usr$1 [L]

    # Attempt to deal with directory listings.
    RewriteCond       %{REQUEST_FILENAME} ^/doc/?$
    # Just list /usr/share/doc for now.
    RewriteRule ^(.+) /usr/share/doc/ [L]

    # Neither worked.  Just pass through to do whatever we would have
    # done before.
    RewriteRule ^(.+) - [PT]
    </IfModule>

    <IfModule !mod_rewrite.c>
    # mod_rewrite isn't available, so fallback to a simple Alias.
    Alias /doc/ /usr/share/doc/
    </IfModule>

These rules will look for http://localhost/doc/foo in both
/usr/share/doc/foo and /usr/doc/foo, which is I believe what Andreas
wanted.  What they won't do, however, is getting a combined directory
listing when someone looks at http://localhost/doc/ itself (the above
rules will just list /usr/share/doc).  If desired, someone could write
a suitable CGI script for the directory listing section above.

For more info, see the Apache URL Rewriting Guide at
<URL:http://www.engelschall.com/pw/apache/rewriteguide/> (also in the
mod_rewrite page in the Apache documentation).

-ccwf


Reply to: