I have to redirect every subdomain in to the domain it goes altering the subdomain title right into a parameter using mod_rewrite, and I am unsure how. Also, I have to "reindex" the parameters to ensure that the subdomain title becames the very first parameter from the uri and also the other parameters from the uri abide by it by their very own order. Something similar to this




Any ideas regarding how to accomplish this using mod_rewrite?


This can be done with one VirtualHost its the subdomains:

<VirtualHost *:80>
    ServerName category.domain.com
    ServerAlias foo.domain.com bar.domain.com

    RewriteEngine On
    RewriteCond %{HTTP_HOST} (.*).domain.com
    RewriteRule (.*) http://domain.com/%1$1 [R=301,QSA,L]

For this to operate correctly, you'll want something set because the ServerName, so just pick one and list the relaxation of the subdomains around the ServerAlias line.

You could have multiple ServerAlias lines, which means you could break them into multiple lines for readability for those who have a lot of subdomains.

Within the RewriteRule, the %1 matches the very first matched up pattern in preceding RewriteCond lines.