Proposal: Friendly URLs on SAFE Browser

As far as I know, due to the absence of a back-end, most SAFE sites will be presented as “single page application” (SPA) apps. But unless we want to see things like “safe://domain/index.html#about” or even worse “safe://domain/about.html” (instead of “safe://domain/about”), we need some way to rewrite URLs.

In the Apache world this is achieved with a .htaccess file and some rewrite rules, but what about SAFE? Is there any plan to deal with rewritings/friendly URLs on SAFE?

EDIT: title was “Friendly URLs - how to?”, but it became to a proposal.

4 Likes

Here’s a simple proposal for the SAFE Browser:

  1. SAFE browser will always look for a “.rewrite” file in the root;
  2. This “.rewrite” file contains a list of tuples, one per line, in the following format: [regex] [rewrite]
    Ex.:

# [regex] [rewrite]
^assets/(.) /assets/$1
(.
) index.html

In this example, www.domain/about will redirect to index.html that, using HTML5’ history interface, will properly render the correct page. In this example, everything but “/assets” files will be redirected to index.html.

Alternatively, rules can be in the meta of the domain’s home dir.

what is a tuple?

And from what I’m understanding you’re suggesting to create a list of internal bookmarks where files are linked to scripts and then redirected automatically. Am I following you so far?

http://openbookproject.net/thinkcs/python/english3e/tuples.html

Sorry about the “tuples”, let me re-phrase it for your better understanding:

.rewrite file contains a list of rules. Each rule is composed by a) a regex expression and b) a replacement string.

This is a classical regex replacement mechanism, but using a simplified notation. The usual syntax is: /[regex expression]/[replacement string]/[options].

Rewriting is how the web works to provide friendly URLs. It’s how Apache, nginx, and all others do it. Currently, if you want to have friendly URLs, you need to have a list of regular expressions that redirects to an index.html. Then, index.html can, for example, use the history interface to render the appropriate page.

This is the current standard. And in my opinion, it’s better to have a mechanism that developers are already familiar with than to create a new one.