简体   繁体   English

使用.htaccess重定向除www以外的虚拟子域

[英]Use .htaccess to redirect virtual subdomains except for www

I'm already using http.d to drive (via 301 redirect) all non-www traffic to the www version of the site. 我已经在使用http.d来驱动(通过301重定向)所有非www流量到网站的www版本。 Ie example.com redirects to www.example.com. 即example.com重定向到www.example.com。

This works perfectly. 这很完美。

I would now like to allow users to set up virtual subdomains. 我现在想允许用户设置虚拟子域。 So, if somebody visits bob.example.com, I'd like mod_rewrite to actually serve the page www.example.com/page.php?user=bob. 因此,如果有人访问bob.example.com,我希望mod_rewrite实际提供www.example.com/page.php?user=bob页面。

Since all of my Google history is set up to index the www version of the site, I don't want to lose that, so I want www excluded. 由于我所有的Google历史记录都设置为索引网站的www版本,因此我不想失去它,所以我希望排除www。

Thanks for your help. 谢谢你的帮助。

You can use this rule in your DOCUMENT_ROOT/.htaccess file: 您可以在DOCUMENT_ROOT/.htaccess文件中使用此规则:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(?!www\.)([^.]+)\.example\.com$ [NC]
RewriteRule ^ page.php?user=%1 [L,QSA]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM