Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I used Apache's virtual host for a ton of subdomains for greptweet.com, where each twitter username is a subdomain, like <username>.greptweet.com. Problem is ... subdomains can't have underscores! :)

Now I've restructured the site, I want to permanently redirect all users that are going to the subdomain to the path:

<username>.greptweet.com to the path structure greptweet.com/u/<username>

e.g. http://kaihendry.greptweet.com/ to http://greptweet.com/u/kaihendry/

Ideally I'd like to achieve this nearly in the Apache httpd.conf <VirtualHost> stanza instead of writing bits into /srv/www/

share|improve this question

1 Answer 1

Something like this would work:

<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>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.