【发布时间】:2020-05-29 20:02:45
【问题描述】:
不太确定解决此问题的最佳方法。但我正在尝试创建的内容与通用共享主机提供商非常相似,但在 Symfony 中。
假设我有一个网站 myawesomesite.com。用户可以注册并拥有自己的空间 myawesomesite.com/sites/theusersdomain.com/。
我可以创建这样的路线,没问题...
/**
* @Route("/sites/{client_website_address}", name="client_public")
*/
public function _client_index($client_website_address) {
return new Response($client_website_address);
}
最终我希望用户有自己的域名指向这条路线。这可以通过 Apache VirtualHost 完成吗? (SSL/TLS 证书我需要这个)我已经这样做了,但不知道如何指向路由。
UseCanonicalName Off
LogFormat "%V %h %l %u %t \"%r\" %s %b" vcommon
#Client websites
<VirtualHost *:80>
VirtualDocumentRoot "/var/www/html/myawesomesite.com/public"
<Directory "/var/www/html/myawesomesite.com/public">
Options -Indexes +FollowSymLinks
AllowOverride All
</Directory>
</VirtualHost>
我还需要添加到我当前的 .htaccess 文件吗?我当前的 .htaccess 是 Symfony 的标准文件。(我稍后可能会将 .htaccess 文件与 VirtualHosts 结合起来)
<IfModule mod_rewrite.c>
RewriteEngine On
# Determine the RewriteBase automatically and set it as environment variable.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
# If the requested filename exists, simply serve it.
# We only want to let Apache serve files and not directories.
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
# Rewrite all other queries to the front controller.
RewriteRule .? %{ENV:BASE}/index.php [L]
</IfModule>
我已经研究了一些类似的东西,但没有任何方法可以实现这一点,除非有更好的方法?我需要域是动态的。用户将转到他们的 URL,他们的文档根目录应该是我的 Symfony 路由 (https://myawesomesite.com/sites/theusersdomain.com/)。
【问题讨论】: