URL Design with Lasso

3,855 views
3,731 views

Published on

Presentation from Lasso Summit 2006. Also see the paper at http://www.scribd.com/doc/919286/URL-Design

Published in: Business, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
3,855
On SlideShare
0
From Embeds
0
Number of Embeds
33
Actions
Shares
0
Downloads
60
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

URL Design with Lasso

  1. 1. URL Design – Methods to Use Friendly URLs
  2. 2. URL Design – Methods to Use Friendly URLs   by Johan Sölve Montania System AB, Sweden www.montania.se
  3. 3. URL Design – Methods to Use Friendly URLs   by Johan Sölve Montania System AB, Sweden www.montania.se • Software and consulting company • Business administration solutions for small- and medium-sized business
  4. 4. URL Design 2 of 41
  5. 5. URL Design 2 of 41
  6. 6. URL Design 2 of 41
  7. 7. URL Design 2 of 41
  8. 8. URL Design 2 of 41
  9. 9. A URL is not a Filename 3 of 41
  10. 10. A URL is not a Filename • Servertotechnology file us think that a URL makes maps a physical 3 of 41
  11. 11. A URL is not a Filename • Servertotechnology file us think that a URL makes maps a physical • This is not how things are intended 3 of 41
  12. 12. A URL is not a Filename • Servertotechnology file us think that a URL makes maps a physical • This is not how things are intended • A URL is a reference to a resource 3 of 41
  13. 13. A URL is not a Filename • Servertotechnology file us think that a URL makes maps a physical • This is not how things are intended • A URL is a reference to a resource • Disconnect the URL from the server’s file system 3 of 41
  14. 14. A URL is not a Filename • Servertotechnology file us think that a URL makes maps a physical • This is not how things are intended • A URL is a reference to a resource • Disconnect the URL from the server’s file system • Design URLs! 3 of 41
  15. 15. A URL is not a Filename • Servertotechnology file us think that a URL makes maps a physical • This is not how things are intended • A URL is a reference to a resource • Disconnect the URL from the server’s file system • Design URLs! • Do URL Mapping! 3 of 41
  16. 16. Choosing URLs 4 of 41
  17. 17. Choosing URLs • Short – easy to share 4 of 41
  18. 18. Choosing URLs • Short – easy to share • Memorable – easy to remember 4 of 41
  19. 19. Choosing URLs • Short – easy to share • Memorable – easy to remember • Bookmark-able – easy to come back 4 of 41
  20. 20. Choosing URLs • Short – easy to share • Memorable – easy to remember • Bookmark-able – easy to come back • An aid in site navigation – easy to use 4 of 41
  21. 21. Choosing URLs 4 of 41
  22. 22. Choosing URLs 5 of 41
  23. 23. Choosing URLs • Guess-able – easy to find what you’re looking for 5 of 41
  24. 24. Choosing URLs • Guess-able – easy to find what you’re looking for 5 of 41
  25. 25. Choosing URLs • Guess-able – easy to find what you’re looking for 5 of 41
  26. 26. Choosing URLs 5 of 41
  27. 27. Choosing URLs 6 of 41
  28. 28. Choosing URLs • Hackable – easy to navigate 6 of 41
  29. 29. Choosing URLs • Hackable – easy to navigate • Persistent – easy to come back 6 of 41
  30. 30. Choosing URLs • Hackable – easy to navigate • Persistent – easy to come back • Technology Neutral – easy to grow 6 of 41
  31. 31. Choosing URLs • Hackable – easy to navigate • Persistent – easy to come back • Technology Neutral – easy to grow • The acid test 6 of 41
  32. 32. Choosing URLs • Hackable – easy to navigate • Persistent – easy to come back • Technology Neutral – easy to grow • The acid test Can you read a URL to someone over the phone? 6 of 41
  33. 33. URL Design 7 of 41
  34. 34. URL Design • We know how we want the URL to look 7 of 41
  35. 35. URL Design • We know how we want the URL to look • But the a physical file requires us to map a server technology URL to 7 of 41
  36. 36. URL Design • We know how we want the URL to look • But the a physical file requires us to map a server technology URL to • How can we implement URL Design? 7 of 41
  37. 37. URL Design • We know how we want the URL to look • But the a physical file requires us to map a server technology URL to • How can we implement URL Design? URL Mapping 7 of 41
  38. 38. URL Design • We know how we want the URL to look • But the a physical file requires us to map a server technology URL to • How can we implement URL Design? URL Mapping Translate the URL to a Lasso file and parameters 7 of 41
  39. 39. URL Mapping With Lasso 8 of 41
  40. 40. URL Mapping With Lasso • Web Server additions 8 of 41
  41. 41. URL Mapping With Lasso • Web Server additions ‣ Apache mod_rewrite 8 of 41
  42. 42. URL Mapping With Lasso • Web Server additions ‣ Apache mod_rewrite ‣ IISRewrite and ISAPI_Rewrite for IIS 8 of 41
  43. 43. URL Mapping With Lasso • Web Server additions ‣ Apache mod_rewrite ‣ IISRewrite and ISAPI_Rewrite for IIS ‣ WebSTAR Rewrite 8 of 41
  44. 44. URL Mapping With Lasso • Web Server additions ‣ Apache mod_rewrite ‣ IISRewrite and ISAPI_Rewrite for IIS ‣ WebSTAR Rewrite + Robust and powerful 8 of 41
  45. 45. URL Mapping With Lasso • Web Server additions ‣ Apache mod_rewrite ‣ IISRewrite and ISAPI_Rewrite for IIS ‣ WebSTAR Rewrite + Robust and powerful – Dependent on web server 8 of 41
  46. 46. URL Mapping With Lasso • Web Server additions ‣ Apache mod_rewrite ‣ IISRewrite and ISAPI_Rewrite for IIS ‣ WebSTAR Rewrite + Robust and powerful – Dependent on web server Completely outside of Lasso – split logic, more to learn 8 of 41
  47. 47. URL Mapping With Lasso 8 of 41
  48. 48. URL Mapping With Lasso 9 of 41
  49. 49. URL Mapping With Lasso • mod_rewrite example 9 of 41
  50. 50. URL Mapping With Lasso • mod_rewrite example RewriteEngine On #RewriteBase / # Check to see if the request is a real file or directory RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !.*/Security # Everything else gets sent to index.lasso RewriteRule ^(.*)$ /index.lasso?response_filepath=/$1 [QSA,L,NS] 9 of 41
  51. 51. URL Mapping With Lasso • mod_rewrite example RewriteEngine On #RewriteBase / # Check to see if the request is a real file or directory RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !.*/Security # Everything else gets sent to index.lasso RewriteRule ^(.*)$ /index.lasso?response_filepath=/$1 [QSA,L,NS] mod_rewrite can take a bit of black magic to master 9 of 41
  52. 52. URL Mapping With Lasso 9 of 41
  53. 53. URL Mapping With Lasso 10 of 41
  54. 54. URL Mapping With Lasso • Lasso Built-In using error.lasso 10 of 41
  55. 55. URL Mapping With Lasso • Lasso Built-In using error.lasso Use a custom error.lasso page to trap requests for non-existent files 10 of 41
  56. 56. URL Mapping With Lasso • Lasso Built-In using error.lasso Use a custom error.lasso page to trap requests for non-existent files error.lasso 10 of 41
  57. 57. URL Mapping With Lasso 10 of 41
  58. 58. URL Mapping With Lasso 11 of 41
  59. 59. URL Mapping With Lasso • Lasso Built-In using [Define_AtBegin] 11 of 41
  60. 60. URL Mapping With Lasso • Lasso Built-In using [Define_AtBegin] http://reference.omnipilot.com/LDML8Reference.LassoApp?tag=6564 prior to processing any code in the current page. 11 of 41
  61. 61. Define_Atbegin as URL processor 12 of 41
  62. 62. Define_Atbegin as URL processor • Defines code that will be executed before each page on a site is loaded or executed 12 of 41
  63. 63. Define_Atbegin as URL processor • Defines code that will be executed before each page on a site is loaded or executed • Look at the requested URL and map it toany a Lasso file and parameters before loading page for it 12 of 41
  64. 64. Advantages with AtBegin 13 of 41
  65. 65. Advantages with AtBegin • Mostly self-contained within Lasso 13 of 41
  66. 66. Advantages with AtBegin • Mostly self-contained within Lasso • More portable, less things to setup 13 of 41
  67. 67. Advantages with AtBegin • Mostly self-contained within Lasso • More portable, less things to setup • All logic kept within Lasso 13 of 41
  68. 68. Advantages with AtBegin • Mostly self-contained within Lasso • More portable, less things to setup • All logic kept within Lasso • Logic can be integrated with rest of site and database 13 of 41
  69. 69. How Does it Work? 14 of 41
  70. 70. How Does it Work? Visitor http://www.myweather.com/halmstad/weekend.lasso Web Server /halmstad/ Lasso weekend.las so Normal processing 14 of 41
  71. 71. How Does it Work? Visitor Visitor http://www.myweather.com/halmstad/weekend.lasso http://www.myweather.com/halmstad/weekend Web Server /halmstad/ Lasso weekend.las so Web Server Lasso urlhandler_ urlhandler. index.lasso atbegin.lasso inc AtBegin processing 14 of 41
  72. 72. Web Server Configuration 15 of 41
  73. 73. Web Server Configuration • Needed to allow URLs without .lasso (optional) 15 of 41
  74. 74. Web Server Configuration • Needed to allow URLs without .lasso (optional) • Apache config <LocationMatch quot;^[^.]+$quot;> # anywhere without file extensions SetHandler lasso8-handler </LocationMatch> 15 of 41
  75. 75. Web Server Configuration • Needed to allow URLs without .lasso (optional) • Apache config <LocationMatch quot;^[^.]+$quot;> # anywhere without file extensions SetHandler lasso8-handler </LocationMatch> • IIS 6.0 on Windows 2003 Server 15 of 41
  76. 76. Web Server Configuration • Needed to allow URLs without .lasso (optional) • Apache config <LocationMatch quot;^[^.]+$quot;> # anywhere without file extensions SetHandler lasso8-handler </LocationMatch> • IIS 6.0 on Windows 2003 Server Wildcard Application Mapping to send requests to Lasso on a folder-by-folder basis 15 of 41
  77. 77. Lasso Configuration 16 of 41
  78. 78. Lasso Configuration • Define_AtBegin or globally LassoStartup either must be in for a Lasso Site 16 of 41
  79. 79. Lasso Configuration • Define_AtBegin or globally LassoStartup either must be in for a Lasso Site urlhandler_atbegin.lasso <?LassoScript Define_AtBegin: { if: file_exists: '/urlhandler.inc'; include: '/urlhandler.inc'; /if; }; 16 of 41
  80. 80. Lasso Configuration • Define_AtBegin must bedefinesLassoScript that either { } in LassoStartup a Compund Expression, a for a Lasso Site or globally in a variable and can be stored urlhandler_atbegin.lasso executed later. <?LassoScript Define_AtBegin: { if: file_exists: '/urlhandler.inc'; include: '/urlhandler.inc'; /if; }; 16 of 41
  81. 81. Lasso Configuration • Define_AtBegin or globally LassoStartup either must be in for a Lasso Site urlhandler_atbegin.lasso <?LassoScript Define_AtBegin: { if: file_exists: '/urlhandler.inc'; include: '/urlhandler.inc'; /if; }; We want to keep this as generic and transparent as possible 16 of 41
  82. 82. Lasso Configuration • Define_AtBegin or globally LassoStartup either must be in for a Lasso Site urlhandler_atbegin.lasso <?LassoScript Define_AtBegin: { if: file_exists: '/urlhandler.inc'; include: '/urlhandler.inc'; /if; }; We want to keep this as generic and transparent as possible If urlhandler.inc is not present in a virtual host, everything works normally 16 of 41
  83. 83. The URL Handler 17 of 41
  84. 84. The URL Handler • All Lasso requests are passing through one single spot 17 of 41
  85. 85. The URL Handler • All Lasso requests are passing through one single spot • Parse the requested URL by looking at [response_filepath] 17 of 41
  86. 86. The URL Handler • All Lasso requests are passing through one single spot • Parse the requested URL by looking at [response_filepath] • Send the result of the parsing to the actual Lasso file by setting variables 17 of 41
  87. 87. The URL Handler 17 of 41
  88. 88. The URL Handler 18 of 41
  89. 89. The URL Handler • ExampleofURL handler for a News and Products section a site 18 of 41
  90. 90. The URL Handler • ExampleofURL handler for a News and Products section a site urlhandler.inc <?LassoScript // this file is called by the atbegin handler, so it is executed // before any page is being processed. if: response_filepath -> (endswith: '.lasso') || response_filepath -> (endswith: '.lassoapp'); // don't do anything for normal .lasso and .lassoapp requests else; if: response_filepath -> (beginswith: '/news/') || response_filepath -> (beginswith: '/products/'); var: 'url_path'=response_filepath, 'section'=''; $url_path -> (removeleading: '/'); 18 of 41
  91. 91. The URL Handler • ExampleofURL handler for a News and Products section a site if: !($url_path -> endswith: '/'); $url_path += '/'; /if; if: $url_path -> (beginswith: 'news/'); // check for pattern /news/2004/12/31/keyword/ //using regular expression var: 'pathcheck'=(string_findregexp: $url_path, -find='^news/(20d{2})/(0[1-9]|1[0-2])/' + '([^/]+)/([^/]*)'); if: $pathcheck -> size >= 5; $section = 'news'; var: 'newsdate'=($pathcheck -> (get: 2)) + '/' + ($pathcheck -> (get: 3)) + '/' + ($pathcheck -> (get: 4)); 18 of 41
  92. 92. The URL Handler • ExampleofURL handler for a News and Products section a site $newsdate = (date: $newsdate, -format='%Y/%m/%d'); var: 'newskeyword'=($pathcheck -> (get: 5)), var: 'newsextra'=''; if: $pathcheck -> size >= 6; $newsextra=($pathcheck -> (get: 6)); /if; /if; else: $url_path -> beginswith: 'products/'; $section = 'products'; // split up the path in components $url_path = $url_path -> (split: '/'); /if; 18 of 41
  93. 93. The URL Handler • ExampleofURL handler for a News and Products section a site // run site // use absolute path! $__HTML_REPLY__ = include: '/index.lasso'; abort; /if; /if; ?> 18 of 41
  94. 94. The URL Handler 18 of 41
  95. 95. The URL Handler 19 of 41
  96. 96. The URL Handler • index.lasso now has these variables: 19 of 41
  97. 97. The URL Handler • index.lasso now has these variables: $url_path 19 of 41
  98. 98. The URL Handler • index.lasso now has these variables: $url_path $section tells the site what main section we are in. 19 of 41
  99. 99. The URL Handler • index.lasso now has these variables: $url_path $section tells the site what main section we are in. • For the news section also these variables 19 of 41
  100. 100. The URL Handler • index.lasso now has these variables: $url_path $section tells the site what main section we are in. • For the news section also these variables $newsdate publication date, used when getting the news article from database 19 of 41
  101. 101. The URL Handler • index.lasso now has these variables: $url_path $section tells the site what main section we are in. • For the news section also these variables $newsdate publication date, used when getting the news article from database $newskeyword an identification string for the news article 19 of 41
  102. 102. The URL Handler • index.lasso now has these variables: $url_path $section tells the site what main section we are in. • For the news section also these variables $newsdate publication date, used when getting the news article from database $newskeyword an identification string for the news article $newsextra optional extra item, for example ‘comments’ Try it 19 of 41
  103. 103. Running The Site 20 of 41
  104. 104. Running The Site • [Define_AtBegin] will never output anything to the web page by itself 20 of 41
  105. 105. Running The Site • [Define_AtBegin] will never output anything to the web page by itself • Explicitly put the output to the page buffer 20 of 41
  106. 106. Running The Site • [Define_AtBegin] will never output anything to the web page by itself • Explicitly put the output to the page buffer • [abort] so Lasso doesn’t try to run the requested file again afterwards 20 of 41
  107. 107. Running The Site • [Define_AtBegin] will never output anything to the web page by itself • Explicitly put the output to the page buffer • [abort] so Lasso doesn’t try to run the requested file again afterwards $__HTML_REPLY__ = include: '/index.lasso'; abort; 20 of 41
  108. 108. Error Handling 21 of 41
  109. 109. Error Handling • The requested URL is not a physical file so a File Not Found can technically not happen 21 of 41
  110. 110. Error Handling • The requested URL is not a physical file so a File Not Found can technically not happen • For invalid URLs a be provided status code and proper HTTP error page should 21 of 41
  111. 111. Error Handling • The requested URL is not a physical file so a File Not Found can technically not happen • For invalid URLs a be provided status code and proper HTTP error page should • Invalid URL: 404 Not Found 21 of 41
  112. 112. Error Handling • The requested URL is not a physical file so a File Not Found can technically not happen • For invalid URLs a be provided status code and proper HTTP error page should • Invalid URL: 404 Not Found • URL no longer available: 410 Gone 21 of 41
  113. 113. Error Handling • The requested URL is not a physical file so a File Not Found can technically not happen • For invalid URLs a be provided status code and proper HTTP error page should • Invalid URL: 404 Not Found • URL no longer available: 410 Gone • See http://www.w3.org/Protocols/HTTP/1.1/ spec.html#Status-Codes 21 of 41
  114. 114. Error Handling 21 of 41
  115. 115. Error Handling 22 of 41
  116. 116. Error Handling • Custom tag to set HTTP status http://tagswap.net/setHTTPstatus 22 of 41
  117. 117. Error Handling • Custom tag to set HTTP status http://tagswap.net/setHTTPstatus define_tag: 'setHTTPstatus', -required='statuscode'; // replace status code but keep leading HTTP with version $__http_header__ = (string_replaceregexp: $__http_header__, -find='(^HTTPS+)s+.*?rn', -replace='1 ' + #statuscode + 'rn'); /define_tag; setHTTPstatus: '404 Not Found'; 22 of 41
  118. 118. Watch Out 23 of 41
  119. 119. Watch Out • Important to debugthe site might fail. every carefully. Otherwise page requested on 23 of 41
  120. 120. Watch Out • Important to debugthe site might fail. every carefully. Otherwise page requested on • Can’t use abort as debug method – nothing at all will output 23 of 41
  121. 121. Other uses for AtBegin 24 of 41
  122. 122. Other uses for AtBegin • Virtual Host handling 24 of 41
  123. 123. Other uses for AtBegin • Virtual Host handling • Debugging 24 of 41
  124. 124. Other uses for AtBegin • Virtual Host handling • Debugging • Timing of pages 24 of 41
  125. 125. Other uses for AtBegin • Virtual Host handling • Debugging • Timing of pages • Page optimization 24 of 41
  126. 126. Other uses for AtBegin • Virtual Host handling • Debugging • Timing of pages • Page optimization • Protected downloads 24 of 41
  127. 127. Other uses for AtBegin • Virtual Host handling • Debugging • Timing of pages • Page optimization • Protected downloads • Protection of .inc files 24 of 41
  128. 128. Other uses for AtBegin • Virtual Host handling • Debugging • Timing of pages • Page optimization • Protected downloads • Protection of .inc files • Locking down SiteAdmin.LassoApp 24 of 41
  129. 129. Virtual Host Handling 25 of 41
  130. 130. Virtual Host Handling • Look at the ‘host’ field in the request header 25 of 41
  131. 131. Virtual Host Handling • Look at the ‘host’ field in the request header • Direct the request to the site’s folder 25 of 41
  132. 132. Virtual Host Handling • Look at the ‘host’ field in the request header • Direct the request to the site’s folder - Not for images and other external files 25 of 41
  133. 133. Virtual Host Handling • Look at the ‘host’ field in the request header • Direct the request to the site’s folder - Not for images and other external files - Must use relative paths for includes 25 of 41
  134. 134. Virtual Host Handling 25 of 41
  135. 135. Virtual Host Handling 26 of 41
  136. 136. Virtual Host Handling <?LassoScript var: 'url_path'=response_filepath, 'host'=client_host; // http://tagswap.net/client_host // massage the hostname // www.montania.se turns to montania_se $host -> (removeleading: 'www.'); $host -> (replace: '.', '_'); // direct the request to the virtual host's subfolder $url_path = '/' + $host + $url_path; // run site $__HTML_REPLY__ = include: $url_path; abort; ?> 26 of 41
  137. 137. Debugging 27 of 41
  138. 138. Debugging • If you suspectitthat a page makes Lasso to crash but can’t find 27 of 41
  139. 139. Debugging • If you suspectitthat a page makes Lasso to crash but can’t find • Log the page request to a database in AtBegin 27 of 41
  140. 140. Debugging • If you suspectitthat a page makes Lasso to crash but can’t find • Log the page request to a database in AtBegin • Remove the log entry in AtEnd 27 of 41
  141. 141. Debugging • If you suspectitthat a page makes Lasso to crash but can’t find • Log the page request to a database in AtBegin • Remove the log entry in AtEnd • Leftover entries are pages that have crashed Credit goes to Bil Corry for this idea 27 of 41
  142. 142. Debugging 27 of 41
  143. 143. Debugging 28 of 41
  144. 144. Debugging <?LassoScript define_atbegin( { if: !(global_defined: 'global_pagedebug'); global: 'global_pagedebug' = map; /if; var: 'pagedebug_key'=lasso_uniqueid; $global_pagedebug -> (insert: $pagedebug_key = (date -> format: '%Q %T') + ': ' + server_name + response_filepath); define_atend( { $global_pagedebug -> (remove: $pagedebug_key); } ); }); ?> 28 of 41
  145. 145. Timing of Pages 29 of 41
  146. 146. Timing of Pages • AtEnd handler logs page requests with processing times 29 of 41
  147. 147. Timing of Pages • AtEnd handler logs page requests with processing times <?LassoScript // Script written by Miles // http://tagswap.net/PageLogConsole define_atbegin({ var('start_time' = _date_msec); define_atend({ log_detail(response_localpath + ': ' + (_date_msec - $start_time)); } ); } ); ?> 29 of 41
  148. 148. Page Optimization 30 of 41
  149. 149. Page Optimization • AtEnd to remove extra whitespace http://tagswap.net/lp_page_trim (Bil Corry) 30 of 41
  150. 150. Page Optimization • AtEnd to remove extra whitespace http://tagswap.net/lp_page_trim (Bil Corry) • Gzip compression of pages http://www.omnipilot.com/TotW.1768.8959.lasso (Fletcher Sandbeck) 30 of 41
  151. 151. Protected Downloads 31 of 41
  152. 152. Protected Downloads • Set Lasso to process the download file type 31 of 41
  153. 153. Protected Downloads • Set Lasso to process the download file type • AtBegin handler authorizes the download request 31 of 41
  154. 154. Protected Downloads • Set Lasso to process the download file type • AtBegin handler authorizes the download request • If request is ok, use file_stream to serve the requested file 31 of 41
  155. 155. Protection of .inc Files 32 of 41
  156. 156. Protection of .inc Files • Make .inc files processed by Lasso in Web server 32 of 41
  157. 157. Protection of .inc Files • Make .inc files processed by Lasso in Web server <?LassoScript define_atbegin({ if: response_filepath -> (endswith: '.inc'); $__HTML_REPLY__ = '<h1>Not authorized</h1>'; // set proper result code too abort; /if; } ); ?> 32 of 41
  158. 158. Locking down SiteAdmin.LassoApp 33 of 41
  159. 159. Locking down SiteAdmin.LassoApp • To make from SiteAdmin.LassoApp can only be sure reached the server machine 33 of 41
  160. 160. Locking down SiteAdmin.LassoApp • To make from SiteAdmin.LassoApp can only be sure reached the server machine <?LassoScript define_atbegin({ if: response_filepath -> split: '/' -> last -> (beginswith: 'siteadmin.') && response_filepath -> (endswith: '.lassoapp') && client_ip != '127.0.0.1'; $__HTML_REPLY__ = '<h1>Not authorized</h1>'; // set proper result code too abort; /if; } ); ?> 33 of 41
  161. 161. URL Design 34 of 41
  162. 162. URL Design • Disconnect the URL from the server’s file system 34 of 41
  163. 163. URL Design • Disconnect the URL from the server’s file system • AtBegin lets us do URL mapping all within Lasso 34 of 41
  164. 164. URL Design • Disconnect the URL from the server’s file system • AtBegin lets us do URL mapping all within Lasso • AtBegin has many other interesting uses 34 of 41

×