Forum

URL Toolkit for Stacey

Saadat
27 May 2013, 12:10
Hi!

I have been trying to convert Apache rewrite rules for Stacey App (http://staceyapp.com/) to Hiawatha's URL Toolkit, but so far haven't had much success. I understand that the "ErrorDocument" rule will map to Hiawatha's ErrorHandler inside the VirtualHost configuration, and the RewriteRules will be mapped to "Match <pattern> Rewrite <argument>", but I am having a hard time translating the RewriteConds. Can anyone please help?

.htaccess for Stacey is as follows:

RewriteEngine on

# Some hosts require a rewritebase rule, if so, uncomment the RewriteBase line below. If you are running from a subdirectory, your rewritebase should match the name of the path to where stacey is stored.
# ie. if in a folder named 'stacey', RewriteBase /stacey
#RewriteBase /

ErrorDocument 404 /404.html

# Rewrite any calls to *.html, *.json, *.xml, *.atom, *.rss, *.rdf or *.txt if a folder matching * exists
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !public/
RewriteCond %{DOCUMENT_ROOT}/public/$1.$2 !-f
RewriteRule (.+)\.(html|json|xml|atom|rss|rdf|txt)$ $1/ [L]

# Add a trailing slash to directories
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.)
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ([^/]+)$ $1/ [L]

# Rewrite any calls to /* or /app to the index.php file
RewriteCond %{REQUEST_URI} /app/$
RewriteRule ^app/ index.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ index.php?$1 [L]

# Rewrite any file calls to the public directory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !public/
RewriteRule ^(.+)$ public/$1 [L]


Thanks in advance.

Hiawatha version: 9.1
Operating System: Arch Linux
Hugo Leisink
27 May 2013, 18:07
# Rewrite any calls to *.html, *.json, *.xml, *.atom, *.rss, *.rdf or *.txt if a folder matching * exists
Hiawatha can't do this. This is also something the webapplication should handle, not the webserver. So, Hiawatha will never be able to do this.

# Rewrite any calls to /* or /app to the index.php file
# Rewrite any file calls to the public directory
This is weird. If you rewrite /* to index.php, why have a next rule to handle requests to /public?? I don't get it.

For the rest, it must be something like:
RequestURI exists Return
Match ^/(.+)\.(html|json|xml|atom|rss|rdf|txt)$ Rewrite /$1/
Match ^/app/$ Rewrite /index.php
Match ^/(.*)$ /index.php?$1


This probably needs some more tweaking.
Saadat
28 May 2013, 05:33
Thank you, Hugo! The rules that you provided are working quite nicely. I'll report if something doesn't work, but so far my testing hasn't returned any deal breaker.

Oh, and thanks for the fantastic web server, too.
This topic has been closed.