Getting folder application runs from in Mojolicious Lite

243 Views Asked by At

I want to be able to run my Mojolicious Lite app on shared hosting either from root (www.domain.com/) or subfolder (www.domain.com/misc/mymojoapp/). The app's .pl file always goes to cgi-bin folder of the domain (www.domain.com/cgi-bin/myapp.pl) and I want to use mod_rewrite rules in .htaccess to point to the app. Images/css/js files would be under www.domain.com/misc/mymojoapp/support.

But I cannot figure out how I reliably get misc/mymojoapp/ part of the path so I can pass it into templates. Is there a way?

1

There are 1 best solutions below

3
On
# set apache handler to treat your specified script name(s) as a CGI program
Options +ExecCGI
<Files ~ "(mymojoapp)$">
  SetHandler cgi-script
</Files>
# rewrite any requests into the appRewriteEngine onRewriteCond %{REQUEST_FILENAME} 
!-fRewriteRule ^(.*)$ misc/mymojoapp/$1 [L]

and in your App

# set env variable to use root for pretty URLs

$ENV{SCRIPT_NAME} = '/';

Change the above setting for pretty URL