Zopistas, I'm trying to use SiteAccess to do some redirection on our site. The main idea is this: All folders that do not exist should be redirected to another folder, where they might or might not exist. The way I've tried to implement this is as follows: All calls to URLs except some selected few (more on this later) are redirected to my "artists" folder. Eg: http://mp3.no/bandname is redirected to http://mp3.no/artists/bandname. The SiteAccess rewrite rule looks like this: <dtml-unless "REQUEST.path and REQUEST.path[0][:6]=='manage'"> <dtml-unless "REQUEST.path and REQUEST.path[0]=='players'"> <dtml-unless "REQUEST.path and REQUEST.path[0]=='artists'"> [actual rewrite code] This should except the folders [root]/artists, [root]/players and the manage console. But I would like to have the best way of redirecting everything, except the root of the site and some subdirectories that I list. The above solution is wildly inelegant :) In addition, my crappy piece of redirect also redirects root, which it shouldn't do. To exemplify some more: http://mp3.no should point to root http://mp3.no/artists should point to /artists/index_html http://mp3.no/players should point to /players/index_html http://mp3.no/bandname should point to /artists/bandname/index_html http://mp3.no/anything should point to /artists/anything etc... Evan, do you hear my call of distress? :) Regards, Alexander Limi http://mp3.no
Alexander Limi wrote:
All folders that do not exist should be redirected to another folder, where they might or might not exist.
The way I've tried to implement this is as follows:
All calls to URLs except some selected few (more on this later) are redirected to my "artists" folder.
The SiteAccess rewrite rule looks like this:
<dtml-unless "REQUEST.path and REQUEST.path[0][:6]=='manage'"> <dtml-unless "REQUEST.path and REQUEST.path[0]=='players'"> <dtml-unless "REQUEST.path and REQUEST.path[0]=='artists'">
Evan, do you hear my call of distress? :)
Surely! Two notes to start off... first, the request path is a stack, so 'path[0]' is the *final* path element. You want to test 'path[-1]'. Second, from my own experience I no longer recommend trying to subtly pick out management interactions from regular interactions. Now I just make my use of the management interface explicit by prefixing everything with 'Z'. Such a session starts with 'http://mysite.com/Z/manage'. Now, If you really meant what you said about 'folders that do not exist', then you might want to try: <dtml-let path="REQUEST.path"> <dtml-if path> <dtml-if expr="path[-1]=='Z'"> <dtml-call expr="path.pop()"> <dtml-call expr="REQUEST.setURL(path='Z')"> <dtml-return expr="'done'"> </dtml-if> <dtml-if expr="path[-1] in objectIds()"> <dtml-return expr="'done'"> </dtml-if> </dtml-if> <dtml-call expr="path.append('artists')"> <dtml-call expr="REQUEST.set('SiteRootPATH', '/')"> </dtml-let> If, on the other hand, you really do just want to list names to be left alone, change "path[-1] in objectIds()" to "path[-1] in ['artists', 'players', ...]" Cheers, Evan @ 4-am
Now, If you really meant what you said about 'folders that do not exist', then you might want to try:
<snip code>
If, on the other hand, you really do just want to list names to be left alone, change "path[-1] in objectIds()" to "path[-1] in ['artists', 'players', ...]"
I'm not exactly sure which solution I'll use yet, but thanks. But there is one problem: It still rewrites the root folder to go to the "artists" folder, which I don't want. Is it possible to list it in the list of names in some way? An empty entry or None maybe? (does this value exist in DTML?) Regards, Alexander Limi http://mp3.no
Alexander Limi wrote:
But there is one problem: It still rewrites the root folder to go to the "artists" folder, which I don't want.
Whoops, had my logic a little misarranged. Try this instead (now with annotations!) : <dtml-let path="REQUEST.path"> <dtml-if path> There is a path <dtml-if expr="path[-1]=='Z'"> '/Z/...' explicitly forbids redirection to 'artists' <dtml-call expr="path.pop()"> <dtml-call expr="REQUEST.setURL(path='Z')"> <dtml-elif expr="path[-1] in objectIds()"> Don't redirect existing objects <dtml-else> Everything else goes to 'artists' <dtml-call expr="path.append('artists')"> <dtml-call expr="REQUEST.set('SiteRootPATH', '/')"> </dtml-if> </dtml-if> </dtml-let> Cheers, Evan @ 4-am
participants (3)
-
Alexander Limi -
Alexander Limi -
Evan Simpson