[英]PERL Dancer2, cgi dispatcher and uri_for helper
I have a web interface that i need to maintain and improve, written in a plain old CGI.pm way. 我有一个需要维护和改进的Web界面,它以普通的旧CGI.pm方式编写。 That app is not using templating system neither.
该应用程序也没有使用模板系统。 It's served by apache, like that:
它由apache服务,就像这样:
/var/www/vhost/myapp/cgi-bin/app.cgi
/htdocs/css/styles.css
/htdocs/js/script.js
To add new pages to that app, and make my life easyer, i want to host a Dancer or Dancer2 app next to it, i was thinking about something like that: 为了向该应用程序添加新页面,并使我的生活更轻松,我想在它旁边托管一个Dancer或Dancer2应用程序,我在想这样的事情:
/var/www/vhost/myapp/cgi-bin/app.cgi
/cgi-bin/dispatch.cgi (the one from Dancer2)
/htdocs/css/styles.css
/js/script.js
/dancer_public/...
/dancer2/lib/...
/views/...
/environement/...
In the dispatcher, i'm changing the path to reach the Dancer2 bin/app.psgi. 在调度程序中,我正在更改到达Dancer2 bin / app.psgi的路径。 I added the following .htaccess file to the htdocs dir:
我将以下.htaccess文件添加到htdocs目录中:
# BEGIN dancer application htaccess
RewriteEngine On
RewriteBase /v2
RewriteRule ^/v2$ /cgi-bin/dispatch.cgi [L]
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule v2/(.*) /cgi-bin/dispatch.cgi/$1 [L]
# END dancer application htaccess
By doing that, 通过这样做,
Now that you have the setup, here is where i have an issue, the redirection from v2 to the dancer app is working really well, however, in order to keep consistent, i would like to have the uri_for creating url from v2 , but it's using the SCRIPT_NAME as base url, to show the issue, when i'm creating that url: uri_for('/mypage'), 现在您已经设置好了,这是我遇到的问题,从v2到舞者应用程序的重定向确实运行良好,但是,为了保持一致,我希望uri_for从v2创建url,但是当我创建URL时,使用SCRIPT_NAME作为基本URL来显示问题:uri_for('/ mypage'),
i would like to have that url : example.com/v2/mypage, 我想拥有该网址:example.com/v2/mypage,
but instead i have url example.com/cgi-bin/dispatch.cgi/mypage 但是我有URL example.com/cgi-bin/dispatch.cgi/mypage
SCRIPT_NAME environment variable is containing cgi-bin/dispatch.cgi , i have one terrible hack, that is working, but clearly not the solution, i can have my expected behavior by forcing SCRIPT_NAME to /v2 in the cgi dispatcher, in a BEGIN block. SCRIPT_NAME环境变量包含cgi-bin / dispatch.cgi,我遇到了一个可怕的问题,这是可行的,但显然不是解决方案,我可以通过在BEGIN块中在cgi调度程序中将SCRIPT_NAME强制为/ v2来达到预期的行为。 If someone as a clean solution for that, that would be of a great help!
如果有人将其作为一个干净的解决方案,那将有很大的帮助!
Thanks 谢谢
Have the same problem with D1. D1也有同样的问题。
$ENV{SCRIPT_NAME} = ''; $ ENV {SCRIPT_NAME} ='';
inside dispatch.fcgi helps me. 在dispatch.fcgi内部可以帮助我。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.