Mobile app version of vmapp.org
Login or Join
Reiling115

: Rewrite and virtual hosts for moving subdomains to folder-like requests I am administering a website that previously had mini-sites set up for various physical locations using sub-domains (city1.site.com,

@Reiling115

Posted in: #Apache2 #UrlRewriting

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 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 site.com's IP with no virtual host for city1 will be redirected to site.com)
If that is correct, can I simply set up a rewrite rule for each subdomain that reqrites the URL to 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 site.com city.site.com

Redirect / www.site.com/store-locations-city </VirtualHost>


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

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

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Reiling115

1 Comments

Sorted by latest first Latest Oldest Best

 

@Reiling115

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 site.com city.site.com
RedirectMatch ^/(.+) www.site.com/ RedirectMatch / www.site.com/store-locations-city </VirtualHost>


I'm using 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.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme