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/


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

    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^([^.]+)\.greptweet\.com [NC]
    RewriteRule ^(.*)$ http://greptweet.com/u/%1 [R,L]


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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