这是我的场景:
- 我的 Symfony 3.3 应用程序部署在我的域中,在 Godaddy 的专用主机中使用 cpanel。
- 我的文档根目录不是public_html,它是public_html 中的一个子文件夹
- 通过http我可以正常访问我的网站
- 当我在 cpanel 中成功安装 ssl 证书然后更新 web 文件夹下的 .htaccess 以重定向到 https 时,站点被重定向到 public_html 文件夹,而不是 public_html/subfolder/web,就像 http 一样通常。
请问有人能帮我解决这个问题吗?
我希望将我的 Symfony web 文件夹更改为 public_html 文件夹不是唯一的解决方案。
更新 1
我的 .htaccess 文件
DirectoryIndex app.php
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
# start https
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# end https
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteCond %{HTTP:Authorization} .
RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^ %{ENV:BASE}/app.php [L]
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
RedirectMatch 302 ^/$ /app.php/
</IfModule>
</IfModule>
更新 2
我找到了问题和解决方案,这就是我更改问题标题的原因,因为问题不在于 Symfony,而在于 Apache 虚拟主机配置。
最佳答案
您可以使用安全配置来解决这个问题。这是一个例子 https://symfony.com/doc/current/security/force_https.html
或路由
关于symfony - 如何在 Apache 虚拟主机中使用 ssl 证书 (https) 在 cpanel 托管中配置 Symfony 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48669449/