Forum

htaccess --> nginx --> hiawatha rewrite rule

Gour
7 December 2012, 20:43
Hello!

I'm not at all familiar with Apache's htaccess which I do not consider very human-friendly, so in order to (try to) convert set of rewrite rules for Tiki CMS, I use online htaccess --> nginx converter [winginx.com] (and trying to deduce correct syntax for this forum ).

We're starting simple...Here is htaccess rule:

RewriteRule ^articles$             tiki-view_articles.php                   [L]


and converted produced the following:

location = /articles  { 
rewrite ^(.*)$ /tiki-view_articles.php break;
}


and for it I created the following hiawatha rule:

UrlToolkit {
ToolkitID = tiki-articles
Match ^/articles/(.*)$ Rewrite /tiki-view_articles.php
}


but was getting 404 error and I rewrote it to:

UrlToolkit {
ToolkitID = tiki-articles
Match ^/articles(.*)$ Rewrite /tiki-view_articles.php
}


Do you (if you're familiar with either Apache or Nginx rewriting) find the Hiawaths rule is OK or there is room for improvement?
Hugo Leisink
7 December 2012, 20:54
The pattern from Apache's rule can be copied without change. So, "RewriteRule ^articles$" should become "Match ^articles$". The direct Hiawatha equivalent will then be:
UrlToolkit {
ToolkitID = tiki-articles
Match ^/articles$ Rewrite /tiki-view_articles.php
}


But, I seriously think that there is a better way to solve your issue. Create a new PHP file, say route.php and rewrite every request for a non-existing file to that route.php. In route.php, you determine what other PHP file should have been called. At the end of route.php, simply include that PHP file. In other words, transfer the routing business logic to where it should be: inside your application and away from the webserver's configuration.
Gour
7 December 2012, 21:02
The pattern from Apache's rule can be copied without change. So, "RewriteRule ^articles$" should become "Match ^articles$".


Thank you Hugo for your help and for Hiawatha...I'm really enjoying using it.

But, I seriously think that there is a better way to solve your issue. Create a new PHP file, say route.php and rewrite every request for a non-existing file to that route.php. In route.php, you determine what other PHP file should have been called. At the end of route.php, simply include that PHP file.


I cannot say I do follow 100%, but does it mean that your suggestion would be server-agnostic and won't create any problem for the present Apache/IIS users which are, atm, 1st class citizens?

In other words, transfer the routing business logic to where it should be: inside your application and away from the webserver's configuration.


I really like the idea and considering I'm quite noobish with PHP, I'll suggest it to tiki-devel list. Thank you!
Hugo Leisink
8 December 2012, 08:50
I cannot say I do follow 100%, but does it mean that your suggestion would be server-agnostic and won't create any problem for the present Apache/IIS users which are, atm, 1st class citizens?

I'm very sure that my solution will work without any problem and will make tiki less Apache-only.
Gour
8 December 2012, 11:53
I'm very sure that my solution will work without any problem and will make tiki less Apache-only.


That would be great.

I sent a post to the tiki-devel list, but, so far, one concern is backward compatibility with many tiki-based sites which are currently online.
Hugo Leisink
8 December 2012, 11:59
That should also not be a concern, because I'm also very sure that it's perfectly possible to create a PHP script that has the same functionality as the URL rewrite rules.

The only thing current tiki-users have to do is to place the new route.php on their server and change the current URL rewriting rules with the rewrite-requests-for-non-existing-files-to-route.php one.
Marc Laporte
20 December 2012, 04:57
So we are discussing / planning how to best improve this:
http://dev.tiki.org/URL+Rewriting+Revamp

Thanks!
This topic has been closed.