这可能很奇怪,但我需要为两个不同的应用程序设置一个域,一个是用 Symfony3 构建的,而另一个是用 Wordpress 构建的。两个网站都在同一服务器上。
www.example.com -> wordpress
www.example.com/custom-slug -> symfony3
使用 Apache2 可以实现这一点吗?
感谢您的帮助
您可以使用
Alias
指令将与模式 /custom-slug/* 匹配的所有请求映射到 Symfony 应用程序。所有其他 URL 都将从 WordPress 提供。
示例虚拟主机:
<VirtualHost *:80>
ServerName www.example.com
ServerAdmin webmaster@localhost
DocumentRoot /your_web_root/www_example_com/wordpress/
# All URLs begining with /custom-slug will be fetched from the symfony app
Alias "/custom-slug" "/your_web_root/www_example_com/symfonyApp/web/"
<Directory /your_web_root/www_example_com/wordpress/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
<Directory /your_web_root/www_example_com/symfonyApp/web/>
AllowOverride None
Order Allow,Deny
Allow from All
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
</Directory>
</VirtualHost>
上面的解决方案工作完美,但我花了一段时间才弄清楚,所以我想我可以与您分享我在 Redhat Linux 上的版本和安全端口 443:
在 /etc/httpd/conf.d 中为其创建一个虚拟conf文件,例如 mycustom.conf 并在其中写入以下内容:
<VirtualHost *:443>
ServerName mydomain.u.com
ServerAdmin [email protected]
DocumentRoot /var/www/html
# This is your Symfony or second website/application location such as: mydomain.u.com/mysymfonywebsite
Alias "/mysymfonywebsite" "/var/www/SymfonyProject/public/"
SSLEngine On
SSLCertificateKeyFile /etc/pki/tls/private/l.key
SSLCertificateFile /etc/pki/tls/certs/l.crt
SSLCertificateChainFile /etc/pki/tls/certs/chain.crt
ErrorLog logs/error.log
CustomLog logs/access.log combined
# This is your wordpress or any website you want
<Directory /var/www/html/>
Options FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
# This is your Symfony web application configuration continued
<Directory /var/www/SymfonyProject/public>
Options FollowSymLinks MultiViews
AllowOverride All
Require all granted
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
</Directory>
您有问题请随时提出:)祝您好运!
D.