Lasso Soft Inc. > Home

  • Articles

Virtual URLs without define_atbegin

The following is an alternative to using define_atbegin in a LassoStartup folder for virtual URLs on Apache 2.2.

In this method because all virtual URLs get rewritten, response_filepath and response_path return the location of the URL handler, not the virtual URL. Therefore a custom tag to replace these tags is required.

Huge thanks to Bil Corry for his help and amazing skills.

Virual Host Directive for Apache 2.2

----- BEGIN VIRTUAL HOST DIRECTIVES for APACHE 2.2 -----

<ifmodule mod_rewrite.c="">
# Turn mod_rewrite on.
    RewriteEngine on

# Honor the server-wide rewrite rules if any exist.
    RewriteOptions inherit

# Debug rewrite rules for use in development only.
# RewriteLogLevel can be 1-9.
# Configure the path to the rewrite log file.
# Do NOT enable in production or your log file will get huge quickly.
#   RewriteLog /private/var/log/apache2/rewrite.log
#   RewriteLogLevel 9

# Lasso gets all virtual files and directories
# that don&#39;t have an extension between 1 and 8 characters long
    RewriteCond %{REQUEST_URI}  !^.*\.[^.]{1,8}$
    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
    RewriteRule  (.*) /_urlhandler.lasso [L,NS,PT,E=X-VIRTUAL-PATH:$1]
    RequestHeader unset X-VIRTUAL-PATH
    RequestHeader set X-VIRTUAL-PATH %{X-VIRTUAL-PATH}e env=X-VIRTUAL-PATH
</ifmodule>

----- END VIRTUAL HOST DIRECTIVES for APACHE 2.2 -----

Custom Tag to replace response_filepath and response_path

----- BEGIN Custom Tag to replace response_filepath and response_path -----
[
// Overload response_filepath and response_path.
// Place in LassoStartup for the site.

define_tag('filepath',-namespace='response',-priority='high',-criteria=(params->size == 0));
    local('vpath') = string;
    protect;
        #vpath = string_findregexp(client_headers,-find='(?im)^X-VIRTUAL-PATH:\\s*(.*)$')->get(2)->trim&;
    /protect;
    if(#vpath->size);
        return(#vpath);
    else;
        return(response_filepath(-original));
    /if;
/define_tag;

global('response_path') = tags_find('response_path');
define_tag('path',-namespace='response',-priority='replace');
    local('vpath') = string;
    local('vfilepath') = string;
    protect;
        #vpath = string_findregexp(client_headers,-find='(?im)^X-VIRTUAL-PATH:\\s*(.*)$')->get(2)->trim&;
        #vfilepath = response_filepath->split('/')->last;
        #vpath->removetrailing(#vfilepath);
    /protect;
    if(#vpath->size);
        return(#vpath);
    else;
        return(global('response_path')->run);
    /if;
/define_tag;
]
----- END Custom Tag to replace response_filepath and response_path -----

----- BEGIN /_urlhandler.lasso -----
[
// Optionally add logic to determine what gets processed by your framework.
content_body = include('/myframework.lasso');
content_body -> trim;
abort;
]
----- END /_urlhandler.lasso -----

Author: Steve Piercy
Created: 23 Jan 2010
Last Modified: 20 Jun 2012

Comments

No comments found
You must be logged in to comment.

Please note that periodically LassoSoft will go through the notes and may incorporate information from them into the documentation. Any submission here gives LassoSoft a non-exclusive license and will be made available in various formats to the Lasso community.

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft