Personal tools
You are here: Home Blog 2009 Apache mod_rewrite for moved directories and folders

Apache mod_rewrite for moved directories and folders

Posted by Lee Joramo at Oct 15, 2009 10:15 AM |
Filed under: ,

Plone has a great system for merging, compressing, versioning, refreshing and serving only the appropriate CSS and javascript files. Learn my about Using the Resource Registries to control CSS and Javascript in Plones documentation.

Recently, a client contracted with a technical data provider. This data is hosted on the provider's servers who integrated our Plone theme as the basis of the design on their hosted site. Unfortunately, the design was hard linked to the temporary merged CSS & JS files hosted on the Plone site. When these files updated they would get a new name, and in the process break the data provider's site design.

To solve this problem on our end (yes, it should be resolved at the source ... ) I created a frozen version of the merged files and placed them in a Zope folder.

The external site was still linking to files in the wrong place, so I created an Apache rewrite rule which came to the rescue. An example of the URL which needed conversion:

http://example.org/portal_css/exampleSkin/ploneStyles2326.css

Was then translated to this:

http://example.org/zopeDirectoryForFrozenFiles/ploneStyles2326.css

Using this Apache Rewrite rule:

    <IfModule mod_rewrite.c>
        RewriteEngine On
        
        # improper linkage to /home and not raw domain
        RewriteRule ^/home$ http://marillacclinic.org/
        
        # css rewrite rule for third party static css
        RewriteRule portal_css/exampleSkin/(.*)$ http://example.org/new-directory/$1

        # js rewrite rule for third party static css
        RewriteRule portal_javascripts/exampleSkin/(.*)$ http://example.org/new-directory/$1
        
        #finally the standard plone virtual hosting rewrite rule
        RewriteRule ^/(.*) \
        http://localhost:11080/VirtualHostBase/http/%{SERVER_NAME}:80/mount-example/example/VirtualHostRoot/$1 [L,P]
    </IfModule>

 

Document Actions