我在 Apache VirtualHost 文件中的配置是:
<VirtualHost xxx.xxx.xxx.xxx:80>
ServerAdmin [email protected]
ServerName abcdefg.com
ServerAlias www.abcdefg.com
DocumentRoot /var/www/abcdefg.com/public/abcdefg/current/public/
ErrorLog /var/www/abcdefg.com/logs/error.log
CustomLog /var/www/abcdefg.com/logs/access.log combined
<Directory /var/www/abcdefg.com/public/abcdefg/current/public>
AllowOverride all
Options -MultiViews
</Directory>
<Location /blog>
PassengerEnabled off # turn off Passenger for /blog subdirectory
</Location>
<Location /support>
PassengerEnabled off # turn off Passenger for /support subdirectory
</Location>
<Location /stats>
PassengerEnabled off # turn off Passenger for /stats subdirectory
</Location>
RewriteEngine On
RewriteRule ^/blog/?(.*)$ /var/www/abcdefg.com/blog/public_html/$1 [NC,QSA,L]
RewriteRule ^/support/?(.*)$ /var/www/abcdefg.com/support/public_html/$1 [NC,QSA,L]
RewriteRule ^/stats/?(.*)$ /var/www/abcdefg.com/stats/public_html/$1 [NC,QSA,L]
RewriteCond %{HTTP_HOST} ^www\.abcdefg\.com [NC]
RewriteRule ^(.*)$ http://abcdefg.com/$1 [L,R=301]
</VirtualHost>
<VirtualHost xxx.xxx.xxx.xxx:443>
SSLEngine On
SSLCertificateFile /etc/apache2/ssl/apache.pem
SSLCertificateKeyFile /etc/apache2/ssl/apache.key
ServerAdmin [email protected]
ServerName q1
DocumentRoot /var/www/abcdefg.com/public/abcdefg/current/public/
ErrorLog /var/www/abcdefg.com/logs/error.log
CustomLog /var/www/abcdefg.com/logs/access.log combined
</VirtualHost>
当我输入 时www.abcdefg.com
,结果http://abcdefg.com//
后面会出现双斜线。我该如何修复这个问题?
答案1
罪魁祸首是你的最后一个RewriteRule
- 删除之前的尾随斜线$1
:
RewriteRule ^(.*)$ http://abcdef.com$1
这似乎不直观,但原因是第一个/
(即使未输入,也始终隐含)在捕获中被捕获并包含在新的 URL 中。