Forum

Hiawatha prestashop rewrite abomination

tmtech
10 December 2014, 22:31
Dear hiawatha chieftains,

I've just set up prestashop on nginx for a starting company,
using PrestaShop as commerce website,
but I like PolarSSL and Hiawathas security and ssl settings in general,
so I'd like to switch from nginx to hiawatha,
having a bunch of horrifying rewrites + config snippets that block my way.

I tried switching the rewrite with Match and put Rewrite in between
(for example: Match ^/api/?(.*)$ Rewrite /webservice/dispatcher.php?url=$1)

But it still won't do the trick,
I then more or less used brute force and added
RequestURI exists Return
Match ^/.* Rewrite /index.php
to the end of the rewrite block.
That made almost everything work (seo urls).
Except for shopping cart and search, which is obviously important .

You would help our business a lot if you could try to translate the below nginx rewrites to hiawatha.
Why can't I see donate buttons here by the way ?
       # Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
location ~ /\. {
deny all;
access_log off;
log_not_found off;
}

rewrite ^/api/?(.*)$ /webservice/dispatcher.php?url=$1 last;
rewrite ^/([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$1$2$3.jpg last;
rewrite ^/([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$1$2$3$4.jpg last;
rewrite ^/([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$1$2$3$4$5.jpg last;
rewrite ^/([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$1$2$3$4$5$6.jpg last;
rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$5/$1$2$3$4$5$6$7.jpg last;
rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$1$2$3$4$5$6$7$8.jpg last;
rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$7/$1$2$3$4$5$6$7$8$9.jpg last;
rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$7/$8/$1$2$3$4$5$6$7$8$9$10.jpg last;
rewrite ^/c/([0-9]+)(\-[\.*_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.jpg$ /img/c/$1$2$3.jpg last;
rewrite ^/c/([a-zA-Z_-]+)(-[0-9]+)?/.+\.jpg$ /img/c/$1$2.jpg last;
rewrite ^/images_ie/?([^/]+)\.(jpe?g|png|gif)$ /js/jquery/plugins/fancybox/images/$1.$2 last;
try_files $uri $uri/ /index.php$is_args$args;
error_page 404 /index.php?controller=404;

location ~* \.(gif)$ {
expires 2592000s;
}
location ~* \.(jpeg|jpg)$ {
expires 2592000s;
}
location ~* \.(png)$ {
expires 2592000s;
}
location ~* \.(css)$ {
expires 604800s;
}
location ~* \.(js|jsonp)$ {
expires 604800s;
}
location ~* \.(js)$ {
expires 604800s;
}
location ~* \.(ico)$ {
expires 31536000s;
}

location ~ \.php$ {
try_files $uri =404;
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/system/php.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors on;
}
}

Again, please help, I'm overwhelmed with translating the config, it would row nicely into your Howto rewrite configs page though!

Hiawatha version: 9.9
Operating System: Debian 7
Hugo Leisink
11 December 2014, 11:37
That's one nasty URL rewrite rule you have there.
UrlToolkit {
ToolkitID = prestashop
Match ^/api/?(.*)$ Rewrite /webservice/dispatcher.php?url=$1
Match ^/([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ Rewrite /img/p/$1/$1$2$3.jpg
Match ^/([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ Rewrite /img/p/$1/$2/$1$2$3$4.jpg
Match ^/([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ Rewrite /img/p/$1/$2/$3/$1$2$3$4$5.jpg
Match ^/([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ Rewrite /img/p/$1/$2/$3/$4/$1$2$3$4$5$6.jpg
Match ^/([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ Rewrite /img/p/$1/$2/$3/$4/$5/$1$2$3$4$5$6$7.jpg
Match ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ Rewrite /img/p/$1/$2/$3/$4/$5/$6/$1$2$3$4$5$6$7$8.jpg
Match ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ Rewrite /img/p/$1/$2/$3/$4/$5/$6/$7/$1$2$3$4$5$6$7$8$9.jpg
Match ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ Rewrite /img/p/$1/$2/$3/$4/$5/$6/$7/$8/$1$2$3$4$5$6$7$8$9$10.jpg
Match ^/c/([0-9]+)(\-[\.*_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.jpg$ Rewrite /img/c/$1$2$3.jpg
Match ^/c/([a-zA-Z_-]+)(-[0-9]+)?/.+\.jpg$ Rewrite /img/c/$1$2.jpg
Match ^/images_ie/?([^/]+)\.(jpe?g|png|gif)$ Rewrite /js/jquery/plugins/fancybox/images/$1.$2
RequestURI exists Return
Match .*\?(.*) Rewrite /index.php?$1
Match .* Rewrite /index.php
}

VirtualHost {
...
UseToolkit = prestashop
ErrorHandler = 404:/index.php?controller=404
}


Do yourself a favor and report this monstrous URL rewriting rule as a bug, because that is what it is. It's the result of bad programming. A well written web application only requires that URL's for non-existing files are rewritten to /index.php (or whatever default entry script). The rest of the routing should be handled by the application.


TikiCMS also had a very ugly rewriting rule. They followed my advice [dev.tiki.org]. and it's now an application much more easy to get going, much less webserver dependent.
tmtech
11 December 2014, 17:08
Thank you very much, works flawless!

Yes I'm not a fan of these huge rewrites aswell, but rather bloated Shopsystems like prestashop don't get recoded as "easy" as tiki I'd say, or don't want to take the extra effort to fix the problem. They often go the "never touch a running system" way.

Well I'll now get myself a neat ssl cert and enjoy your webserver .
Nice to see that you've changed some SSL cipher orders, im using calomel ssl verification, had a blue shield (80% well SSL) because hiawatha picked some SHA1 cipher, now it picks SHA256 AEAD GCM with green shield 100% perfect SSL, good job on that, too!
I wonder what Hiawatha 10 would bring, probably something groundbreaking .

Have nice holidays, sir.
This topic has been closed.