Webmasters Stack Exchange is a question and answer site for pro webmasters. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am administering a website that previously had mini-sites set up for various physical locations using sub-domains (city1.site.com, town2.site.com, etc.) and I now need to disable these mini-sites. They are no longer being used and reside on a server that is obsolete. However I want the users that may have or find old links to be directed to the Magento store running on a new server with a request that looks like www.site.com/store-locations-city1 so that the user gets that store's information page.

If I simply change the DNS entries for those subdomains to point to the web store server, and there is no virtual host configuration, they will be redirected (I believe, haven't tested) to the default virtual host. (i.e. city1.site.com directed to www.site.com's IP with no virtual host for city1 will be redirected to www.site.com)

If that is correct, can I simply set up a rewrite rule for each subdomain that reqrites the URL to www.site.com/store-location-[city/town] ? Where would I configure those rewrites?

If this doesn't work the way I think it does, what alternative do I have?

Upon further reading, I tested with one site and these are my results: without a virtual host, I can verify that the url is automatically redirected to the default virtual host.

If the url originall contained anything it doesn't change this behavior.

I added a virtual host for that subdomain with:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName city.site.com
    ServerAlias www.site.com city.site.com

    Redirect / http://www.site.com/store-locations-city

which works unless the original URL had something else in it, say city1.site.com/contact which results in a 404 because www.site.com/store-locations-city1contact doesn't exist.

I still need to know how and where to rewrite anything other than / in this case

share|improve this question
up vote 0 down vote accepted

I found the perfect solution: Use RedirectMatch

I will have a virtual host configured for each mini-site that will look like this:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName city.site.com
    ServerAlias www.site.com city.site.com
    RedirectMatch ^/(.+) http://www.site.com/$1
    RedirectMatch / http://www.site.com/store-locations-city

I'm using $1 on the first RewriteMatch because the site is configured to perform searches on 404 urls. This should be more user-friendly than just directing to the index. I do not know what effect this will have on SEO, though.

share|improve this answer

Your Answer


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.