Forum

Symphony REST API extension URL rewrite conversion

David Oliver
1 May 2012, 19:56
I need to convert the following Apache URL rewrite rule:

RewriteRule ^symphony\/api(\/(.*\/?))?$ extensions/rest_api/handler.php?url=$1&%{QUERY_STRING} [NC,L]


I've tried a few things but am not quite managing. Thanks.
Hugo Leisink
1 May 2012, 20:04
Ah, Symphony... well... what can I say about Symphony...

I haven't tested it, but I think it would be something like:
Match ^/symphony\/api(\/(.*\/?))?\?.*$ Rewrite /extensions/rest_api/handler.php?url=$1&$3
Match ^/symphony\/api(\/(.*\/?))?$ Rewrite /extensions/rest_api/handler.php?url=$1



update: forgot to replace RewriteRule with Match / Rewrite.
David Oliver
1 May 2012, 20:44
Thanks Hugo. That's doing something, but I'm getting "API is private. Authentication failed." despite having included the authorisation token.

An example call is:

http://domain.co.uk/symphony/api/entries/photos/?auth-token=019ccc6e
David Oliver
2 May 2012, 21:25
I think progress is being made The following seems to give what I think is the right result using wigwam (great tool).

Match ^/symphony\/api(\/(.*\/?))?\?(.*)$ Rewrite /extensions/rest_api/handler.php?url=$1&$3
Match ^/symphony\/api(\/(.*\/?))?$ Rewrite /extensions/rest_api/handler.php?url=$1


The API isn't working yet, but I think that's a separate issue and I've asked the author about that. If it ends up working, I'll confirm and let you know where in the Symphony URL toolkit these lines need to go.

Thanks.
David Oliver
10 May 2012, 10:35
Here's my updated symphony URL toolkit that is working with the REST API extension. The new lines are surrounded by extra line breaks for visibility.

UrlToolkit {
ToolkitID = symphony
Match ^/manifest/.* DenyAccess
Match ^/workspace/utilities/.*\.xsl$ DenyAccess
Match ^/workspace/pages/.*\.xsl$ DenyAccess
Match ^/.*\.sql$ DenyAccess
Match ^/favicon.ico$ Return

Match ^/symphony\/api(\/(.*\/?))?\?(.*)$ Rewrite /extensions/rest_api/handler.php?url=$1&$3
Match ^/symphony\/api(\/(.*\/?))?$ Rewrite /extensions/rest_api/handler.php?url=$1
Match ^/symphony\/api Exit

Match ^/image\/(.+\.(jpg|gif|jpeg|png|bmp))$ Rewrite /extensions/jit_image_manipulation/lib/image.php?param=$1
Match ^/symphony\/?$ Rewrite /index.php?mode=administration
RequestURI exists Return
Match (.*)\?(.*) Rewrite $1&$2 Continue
Match ^/symphony(\/(.*\/?))?$ Rewrite /index.php?symphony-page=$1&mode=administration
Match ^/(.*\/?)$ Rewrite /index.php?symphony-page=$1
}


The 'Match ^/symphony\/api Exit' line is to stop any more rewriting from occurring if the REST API is being called, but I expect there may be a tidier way of doing this?
Hugo Leisink
10 May 2012, 16:26
Hmm, if I look at the rewrite rules that Symphony requires, than I have to say that Symphony has a serious design issue.

But thanks, I'll add them to the toolkit rule in the HOWTO page.
David Oliver
10 May 2012, 16:43
Thanks Hugo.

I'd be interested to hear your thoughts on the design issue, of course.
Hugo Leisink
10 May 2012, 16:51
Because of frameworks and CMS-es like Symphony with a, how shall I say it,... 'interesting' approach to good design and security, I decided to write my own framework a few years ago. The result is: Banshee [www.banshee-php.org].

Well designed frameworks and CSM-es rewrite requests for non-existing files to index.php and handle those requests themselves. Maybe some extra rules to improve user experience, but basicly you can say that everything more than that is a sign of bad program design.
David Oliver
10 May 2012, 21:35
Ok, thanks Hugo. I think the 'image' and 'symphony/api' paths result from the fact that Symphony core is relatively light/focused (the developers are very keen on this approach), with additional functionality (image resizing and the REST API in these two cases) being handled via separate extensions. I think apart from these two, and other small things like the favicon, Symphony pretty much does what you describe?

I would like to take a look at Banshee when I get a chance. I like that it uses XSLT - I take it that Banshee outputs XML which I can transform myself into HTML (or whatever)?
Hugo Leisink
11 May 2012, 07:58
The controller in Banshee produces XML, which is passed on to the output class which combines it with the XSLT sheet to from the output (mostly HTML). With every page, you can add ?output=xml to view what the controller has collected. With this option, it's also very easy to let some application communicate with a Banshee-made website.

Look here [www.hiawatha-webserver.org] for an example. It's the XML version of this forum post.
This topic has been closed.