【发布时间】:2018-10-20 17:16:19
【问题描述】:
所以我将我的应用程序托管在 apache 服务器上 /~test/ 下的子目录中
我尝试在路由中添加前缀而没有发生任何事情
我希望所有控制器的所有路由都以/~test/ 开头,而无需我手动将其添加到每个路由。现在,当一条路线到达 / 时,它会超出我的 /~test/ 目录
例如:
/**
* @Route("/login", name="app_login")
*/
public function login(AuthenticationUtils $authenticationUtils): Response
{
}
这条路线我想去/~test/login
我的 .htaccess:
DirectoryIndex index.php
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteCond %{HTTP:Authorization} .
RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^index\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^ %{ENV:BASE}/index.php [L]
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
RedirectMatch 307 ^/$ /index.php/
</IfModule>
</IfModule>
【问题讨论】:
-
将 SetEnv BASE "/test" 添加到 .htaccess
-
@mblaettermann 试过了,把它放在 htaccess 的顶部没有结果,这可能是因为 apache 设置我不知道它是否允许覆盖我无权访问根配置
-
你的 Symfony 版本?同时复制粘贴您的主要网址
-
@Trix symfony 4.1 我的网址在 Intranet 上基本上是 uni.co.uk/~myusername/
-
你想要你的 symfony 应用程序主页在
http://uni.co.uk/~myusername/test/吗?还是别的什么?