我用Apache的虚拟主机为greptweet.com的一大堆子域名,其中每个twitter用户名是一个子域名,如<username> .greptweet.com。 问题是…子域名不能有下划线! 🙂
现在我重新构build了网站,我想永久性地将所有到子域的用户redirect到path:
<username> .greptweet.com添加到path结构greptweet.com/u/ <username>
例如http://kaihendry.greptweet.com/到http://greptweet.com/u/kaihendry/
理想情况下,我希望在Apache的httpd.conf <VirtualHost>节中实现这个function,而不是写入/ srv / www /
像这样的东西可以工作:
<VirtualHost *:80> ServerName kaihendry.greptweet.com ServerAlias *.greptweet.com DocumentRoot /var/www/localhost/htdocs/ Include /etc/apache2/vhosts.d/default_vhost.include <Directory "/var/www/localhost/htdocs"> Order allow,deny Allow from all </Directory> RewriteEngine On RewriteCond %{HTTP_HOST} ^([^.]+)\.greptweet\.com [NC] RewriteRule ^(.*)$ http://greptweet.com/u/%1 [R,L] </VirtualHost>