[SPTUsers] Rewriting URLs

Scot Wilcoxon Scot at Wilcoxon.Org
Sun Mar 16 14:05:05 CST 2003


I'm tinkering with my URLs.  At the moment I'm trying to make them
shorter and separate the URLs from the underlying technology.  Later I
hope to loosen the numerical ID requirement (i.e., a resource for the
Library of Congress might have a URL ending in "/LOC" instead of "/834".

I'll show my Apache mod_rewrite rules at the bottom.  Of course, at
present the SPT pages contain the SPT--PROGRAM?PARAM=VALUE type of links
rather than the abstract ones used in remap.

At present I can do http://www.wilcoxon.org/projplan/browse/175 (show
classifications for parent Id 175),
http://www.wilcoxon.org/projplan/browse/ (show top "Browse Resources"
screen), or http://www.wilcoxon.org/projplan/resource/62 (show resource
62).

However, I encountered some awkwardness which I'm not sure how to
resolve properly.

1. If using /projplan/browse/175, the images try to come from
/projplan/browse/images/.  Same with other pages; the base URL is not
"/projplan/" as with normal entry.  I understand why that is happening,
but don't know the standard way of handling this during rewriting.

2. Inserting "<base href="http://www.wilcoxon.org/projplan/"> in the
*Start.html header makes the browser behave the way I want, with all the
relative references being remapped to the proper directory.  Is this the
proper way to achieve this?  Does PHP have the ability to properly
generate this, or does it have to be specified for each domain/site?

3. I am aware of SPT generating URLs with string functions to assemble
the parameters, including the question mark.  I know I'll have to sweep
through and replace all such code with something like
"makeURL("SPT--BrowseResources.php","ParentId","175")" so a single
function can be modified to deal with various URL formats.  (That will
be a big patch file :-)

Here are my current mod_rewrite rules.  I think I can remove some of the
rules for subdirectory mapping, if <base> is the proper way to shift the
reference.  I have a few other oddities due to my overlaying the SPT
programs over an existing directory -- some old files within the actual
directory for /projplan/ are still accessible.

        RewriteEngine on
        RewriteCond %{HTTP:Authorization} ^(.*)

        # Map browse/NUMBER to browse classification with that number
        RewriteRule ^/projplan/browse/([0-9]+)(.*)$
/var/www/html/SPT/SPT--BrowseResources.php?ParentId=$1$2
[t=application/x-httpd-php,l]
        # If no number given, send to main BrowseResources page
        RewriteRule ^/projplan/browse[/]*$
/var/www/html/SPT/SPT--BrowseResources.php [t=application/x-httpd-php,l]
        # If no specific resource given, send to browse resources
        RewriteRule ^/projplan/resource[/]*$
/var/www/html/SPT/SPT--BrowseResources.php [t=application/x-httpd-php,l]
        # Map resource/NUMBER to browse resource with that number
        RewriteRule ^/projplan/resource/([0-9]+)(.*)$
/var/www/html/SPT/SPT--FullRecord.php?ResourceId=$1$2
[t=application/x-httpd-php,l]
        # Anything beginning with SPT goes to SPT directory
        RewriteRule ^/projplan/(SPT)(.*)$ /var/www/html/SPT/$1$2 [L]
        # Any other references to browse "directory" goes to SPT
directory
        RewriteRule ^/projplan/browse/(.*)$ /var/www/html/SPT/$1 [L]
        # Any other references to resource "directory" goes to SPT
directory
        RewriteRule ^/projplan/resource/(.*)$ /var/www/html/SPT/$1 [L]
        # Anything for a subdirectory under projplan goes to SPT
subdirectory
        RewriteRule ^/projplan/(.+)/(.*)$ /var/www/html/SPT/$1/$2 [L]
        # Reference to old index.html changed to Home page
        RewriteRule ^/projplan/index.*$ /var/www/html/SPT/SPT--Home.php
[t=application/x-httpd-php,l]



More information about the SPTUsers mailing list