我需要在托管域的子文件夹内配置一个symfony应用。 该应用程序注册了一些路由,例如 / hello 。
I need to configure a symfony app inside a subfolder of a hosted domain. The app registers some route, for example /hello.
目录结构为:
/ (http root) /myapp (symfony app) /myapp/.htaccess (invisible redirect) /myapp/public /myapp/src /myapp/vendor /myapp/...使用Apache mod-rewrite,我将所有URL从 www.mysite.test / myapp /...内部重定向到 www.mysite.test / myapp / public /...。
With Apache mod-rewrite I redirect internally all urls from www.mysite.test/myapp/... to www.mysite.test/myapp/public/....
<IfModule mod_rewrite.c> RewriteEngine On RewriteRule ^(.*)$ myapp/public/$1 [L] </IfModule>然后,当我浏览url www.mysite.test / myapp / hello时该应用不会返回 myapp / hello 的路线。
Then when I browse the url www.mysite.test/myapp/hello the app return no route for myapp/hello.
有一种方法可以使用自定义前缀安装所有路由来解决此问题?通过这种方式,控制器可以处理所有带有 / myapp 前缀的url,并且route生成的url也具有该前缀。
There is a way to mount all routes with a custom prefix to solve this problem? In this way the controllers can handle all the url with the /myapp prefix and also the url generated by route has this prefix.
谢谢。
推荐答案也许我找到了未找到路由错误的解决方案。
maybe I found a solution to the route not found error.
- 我在 service.yaml $ c $中定义参数 app.web_root_prefix c>带有url前缀。
- 我在 Kernel.php : $上更改Kernel :: loadRoutes的定义b $ b
- I define a parameter app.web_root_prefix in service.yaml with the url prefix.
- I change the definition of Kernel::loadRoutes on Kernel.php:
在此模式下,所有从.yaml文件加载的路由正确地加上前缀。 另外,您还必须更改security.yaml中的所有路径,并插入前缀%app.web_root_prefix%。
In this mode all routes loaded from a .yaml file are prefixed correctly. Also you must change all paths in security.yaml inserting the prefix %app.web_root_prefix%.
我必须进行更多测试...
I must make more test...
更多推荐
如何在站点子文件夹中配置php symfony4应用(路由问题)
发布评论