我在Apache VirtualHost文件中的configuration是:
<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>
当我inputwww.abcdefg.com ,后面会出现双斜杠http://abcdefg.com// 。 我怎样才能解决这个问题?
罪魁祸首是你最后的RewriteRule – 在$1之前放下斜线:
RewriteRule ^(.*)$ http://abcdef.com$1
这似乎是不直观的,但原因是,第一个/ (总是暗示,即使没有input)被捕获并包含在新的URL中。