我有一个 HTTPS 站点,我想将所有根请求重定向到 www 子域。我尝试了一些命令,但它导致我的服务器 404 错误,因为它是为 .htaccess 制作的。这是我的 sites-available 配置:
<VirtualHost 10.10.10.11:80>
ServerName *.mydomain.com
DocumentRoot /srv/production/www/my_app/current/public/
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
</VirtualHost>
<VirtualHost 10.10.10.11:443>
ServerName www.mydomain.com
DocumentRoot /srv/production/www/my_app/current/public/
<Directory /srv/production/www/my_app/current/public/>
Allow from all
Options -MultiViews
</Directory>
SSLEngine on
SSLCertificateFile /**********
SSLCertificateKeyFile /**************
SSLCertificateChainFile /*************
</VirtualHost>
答案1
HTacess 的等价内容<directory>
。我在 443 vhost 中使用了以下配置:
<Directory /srv/production/www/my_app/current/public/>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
Allow from all
Options -MultiViews
</Directory>