Web Server 7.0, Gallery2, and URL Rewriting

On my personal web site I use Sun Java System Web Server 7.0 and a slew of PHP applications. One of them, Gallery2, has a nice, built in support for URL rewriting. Unfortunately it depends on an extension to Apache called mod_rewrite, and the syntax for the same functionality in Web Server is a bit different. Because of this I've been putting off enabling the feature until I could spare a few hours to research the differences and rewrite the rules. Here's what I came up with.

I've enabled the Gallery2 URL Rewrite module with these options:

  • Show Item
  • Download Item
  • Add Comment
  • View Comments
  • Slideshow
  • RSS
  • Simple RSS Feed
  • Updates Album
  • Popular Album
  • Random Album

My Gallery2 has its own vanity domain, so it's deployed as the root of the URI space.

Gallery2 helpfully generated an htaccess file with these rules (I've annotated for my own understanding - Please point out errors for me):

    RewriteBase /

# Stop processing is the requested file actually exists, or the request is
# for main.php or gallery_remote2.php
# I'm opting to skip this in my translation. It seems a bit unneeded to me.
    RewriteCond  -f [OR]
    RewriteCond  -d [OR]
    RewriteCond  gallery\\_remote2\\.php
    RewriteCond  !/main\\.php$
    RewriteRule .   -   [L]

# If the request is for /popular, and the URI is _not) for /main.php, grab
# Restart the request with the URI changes to the canonical album syntax, and
# append the query string to the end of the new URL (used for paging to pages past
# the front page of the album).
# I notice that all the rules specifically call out main.php in their check. This seems
# overkill to me, so I'll just check once at the beginning of my translation
    RewriteCond  /popular(\\?.|\\ .)
    RewriteCond  !/main\\.php$
    RewriteRule .   /main.php?g2_view=dynamicalbum.PopularAlbum   [QSA,L]

# Same, but for Updates
    RewriteCond  /updates(\\?.|\\ .)
    RewriteCond  !/main\\.php$
    RewriteRule .   /main.php?g2_view=dynamicalbum.UpdatesAlbum   [QSA,L]

# Same, but for Random
    RewriteCond  /random(\\?.|\\ .)
    RewriteCond  !/main\\.php$
    RewriteRule .   /main.php?g2_view=dynamicalbum.RandomAlbum   [QSA,L]

# URI space for downloading items (e.g. "Save Image")
    RewriteCond  /d/([0-9]+)-([0-9]+)/([\^/?]+)(\\?.|\\ .)
    RewriteCond  !/main\\.php$
    RewriteRule .   /main.php?g2_view=core.DownloadItem&g2_itemId=%1&g2_serialNumber=%2&g2_fileName=%3   [QSA,L]

# More of the same, but for the slideshow
    RewriteCond  /v/([\^?]+)/slideshow\\.html(\\?.|\\ .)
    RewriteCond  !/main\\.php$
    RewriteRule .   /main.php?g2_view=slideshow.Slideshow&g2_path=%1   [QSA,L]

# Comment viewing
    RewriteCond  /c/view/([0-9]+)\\.html(\\?.|\\ .)
    RewriteCond  !/main\\.php$
    RewriteRule .   /main.php?g2_view=comment.ShowAllComments&g2_itemId=%1   [QSA,L]

# Comment adding
    RewriteCond  /c/add/([0-9]+)\\.html(\\?.|\\ .)
    RewriteCond  !/main\\.php$
    RewriteRule .   /main.php?g2_view=comment.AddComment&g2_itemId=%1   [QSA,L]

# RSS and Simple RSS rules
    RewriteCond  /rss/([\^\\/\\?]+)(\\?.|\\ .)
    RewriteCond  !/main\\.php$
    RewriteRule .   /main.php?g2_view=rss.Render&g2_name=%1   [QSA,L]
    RewriteCond  /srss/([0-9]+)(\\?.|\\ .)
    RewriteCond  !/main\\.php$
    RewriteRule .   /main.php?g2_view=rss.SimpleRender&g2_itemId=%1   [QSA,L]

# The main URL cruft for viewing most items. I should probably make this my first
# "Real" rule
    RewriteCond  /v/([\^?]+)(\\?.|\\ .)
    RewriteCond  !/main\\.php$
    RewriteRule .   /main.php?g2_path=%1   [QSA,L]
My translated rewrite rules for Web Server 7 are:
# At the top of my default block
# Only enter this stanza if this request is for my vanity VS for photos, and the URI isn't
# for /main.php
<If $urlhost = "photos.foo.com"
     and $uri !~ '/main\\.php'>

    # If the request is for /popular
    <If $url =~ '/popular(\\?(.\*)|())'>
      # Restart the request with the canonical URI (and query string, represented here
      # by "&$2" - Watch for it below too, but notice that the backreference ID changes
      # based on where the parens are in the expression)
      AuthTrans fn="restart" uri="/main.php?g2_view=dynamicalbum.PopularAlbum&$2"
    </If>

    # If the request is for /updates
    <ElseIf $url =~ '/updates(\\?(.\*)|())'>
      # Restart with canonical URI and query string
      AuthTrans fn="restart" uri="/main.php?g2_view=dynamicalbum.UpdatesAlbum&$2"
    </ElseIf>

    # etc
    <ElseIf $url =~ '/random(\\?(.\*)|())'>
      AuthTrans fn="restart" uri="/main.php?g2_view=dynamicalbum.RandomAlbum&$2"
    </ElseIf>

    # etc
    <ElseIf $url =~ '/d/([0-9]+)-([0-9]+)/([\^/?]+)(\\?(.\*)|())'>
      # Restart with the canonical URI and query string, but notice that the backreference
      # for the query match is now $5 rather than $2 above
      AuthTrans fn="restart" uri="/main.php?g2_view=core.DownloadItem&g2_itemId=$1&g2_serialNumber=$2&g2_fileName=$3&$5"
    </ElseIf>

    # etc
    <ElseIf $url =~ '/v/([\^?]+)/slideshow\\.html(\\?(.\*)|())'>
      AuthTrans fn="restart" uri="/main.php?g2_view=slideshow.Slideshow&g2_path=$1&$3"
    </ElseIf>

    # etc
    <ElseIf $url =~ '/c/view/([0-9]+)\\.html(\\?(.\*)|())'>
      AuthTrans fn="restart" uri="/main.php?g2_view=comment.ShowAllComments&g2_itemId=$1&$3"
    </ElseIf>

    # etc
    <ElseIf $url =~ '/c/add/([0-9]+)\\.html(\\?(.\*)|())'>
      AuthTrans fn="restart" uri="/main.php?g2_view=comment.AddComment&g2_itemId=$1&$3"
    </ElseIf>

    # etc
    <ElseIf $url =~ '/rss/([\^\\/\\?]+)(\\?(.\*)|())'>
      AuthTrans fn="restart" uri="/main.php?g2_view=rss.Render&g2_name=$1&$3"
    </ElseIf>

    # etc
    <ElseIf $url =~ '/srss/([0-9]+)(\\?(.\*)|())'>
      AuthTrans fn="restart" uri="/main.php?g2_view=rss.SimpleRender&g2_name=$1&$3"
    </ElseIf>

    # etc
    <ElseIf $url =~ '/v/([\^?]+)(\\?(.\*)|())'>
      AuthTrans fn="restart" uri="/main.php?g2_path=$1&$3"
    </ElseIf>
</If>

I'm pretty happy with the results so far.

Also remember that this set of rules only restarts requests coming into the server; it does nothing to make Gallery2 write the URLs in a shorter, friendlier way. You still have to turn on the Gallery2 URL Rewrite module, etc. This tickles the Gallery2 code that generates the links, etc. One could also use a Web Server output filter to rewrite the HTML from Gallery2 (or any other app) before it hits the wire, but it's better to have the app do it itself.

Comments:

I need a invisible redirect (URL Masking) for a URL running on the diffrent server.How can i do it in SunOne 6.1 webserver.

Thanks
Sandeep

Posted by Sandeep Bajpai on March 04, 2009 at 08:11 PM PST #

For more information about Gallery, refer to http://gallery.menalto.com/.i hope it wil helpfull for u.

Posted by Car hire Melbourne on June 03, 2009 at 03:10 PM PDT #

I need a invisible redirect (URL Masking) for a URL running on the diffrent server.How can i do it in SunOne 6.1 webserver.http://www.gifico.com

Posted by louis vuitton on November 18, 2009 at 02:20 PM PST #

Post a Comment:
  • HTML Syntax: NOT allowed
About

jmccabe

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today