I am working on an application for which I want to create few sub-domains in system, which will be served by Magento application. One example scenario can be creating separate sub-domains for system user's profile. Where User A will have dedicated url user-a.example.com and user B will have a url user-b.example.com. Now, I want to able to map these sub-domains to a controller which will in turn fetch profile information and render it for a particular user.

My current approach involves use of Reverse Proxy on webserver level, where i am mapping subdomains <USER>.example.com to controller http://example.com/user/profile/index/name/<USER>/. Which works well untill i want to perfom some operation based on current url. Even though user sees url with subdomain on the page but in the background request is being made to http://example.com/user/profile/index/name/<USER>/ and Magento system returns full url as current page url.

So, I was wondering if there is any way to bind a subdomain to controller directly in Magento system. I went through few questions posted around this but those does not seems to much useful here.

  • 1
    You can create new store views with the specific subdomains. Depending on the count this might be a really bad idea ;-) Commented Sep 29, 2014 at 18:42
  • @FabianBlechschmidt, Yeah my thought also is same. System will have these urls generated dynamically in good numbers.
    – Lalit
    Commented Sep 30, 2014 at 4:59
  • Mixing DNS resolving with file system requests. Gonna be a pain. Commented Oct 5, 2014 at 3:28
  • @Lalit I wonder if you're able to find a solution for your question?!
    – Aboodred1
    Commented Feb 4, 2015 at 18:47
  • This is exactly what I need, I have only one store, I do not need a multiple store setup, but a single subdomain for some user profiles. Did you get this to work??
    – Vic
    Commented Nov 18, 2015 at 17:09

3 Answers 3


I think your best bet will be to use Apaches URL rewrite functionality for more information see: https://www.addedbytes.com/articles/for-beginners/url-rewriting-for-beginners/ The other option would be to write a completely new router but this will require a good understanding of request processing in Magento. https://shop.vinaikopp.com/grokking-magento/ has some very good information to help you with this.

Magento does not provide this as a standard feature and you will need to do it either via apache or by writing a Magento router.

Something that you could use would be along the lines of:

RewriteCond %{HTTP_HOST} ^([^./]+)\.example\.com$
RewriteCond %1 !=www
RewriteRule ^ /user/profile/index/name/%1/
  • Thanks @Martijn, I am trying do something similar with Reverse proxy approach but with this approach for Magento the current url is the new redirected url. Which defeats my purpose and hence was looking for something that Magento provides.
    – Lalit
    Commented Sep 30, 2014 at 5:05
  • @Lalit I added some additional information. Commented Sep 30, 2014 at 12:02

Try using Magento rewrites instead. Im not sure if this will work, but you can give it a try.


See this question for some more info.

  • Thanks @mbalparda, I doubt this will handle rewrites at subdomain level. Looks like it moreover handles path redirects. Have you tried this with subdomains? does that work?
    – Lalit
    Commented Sep 30, 2014 at 5:08
  • No, i did not tried this but it might worth a shot.
    – mbalparda
    Commented Sep 30, 2014 at 10:48
  • Please note this is deprecated functionality. Commented Feb 8, 2015 at 4:22
  • @RyanStreet please explain your comment.
    – mbalparda
    Commented Feb 11, 2015 at 20:38
  • This method for doing a controller rewrite is deprecated. It is not the modern and accepted way to do rewrites in Magento 1.8 (tagged in this question). Commented Feb 11, 2015 at 20:40

Since subdomains are above Magento in the grand scheme of things, NS A Record mapped with your name server. Then adding the mod_rewrite rule to the controller path as Martijn Schot mentioned would be the ideal approach.

There are other ways to facilitate this also. Such as Replication, creating a path in the file system when a customer registers, with nothing more than a redirect to the proper controller in the application. Keep in mind this may pose scaling problems.

Another option to consider is Wildcard DNS Record.

SO Answer taken from:

You're looking to create a custom A record.

I'm pretty sure that you can use wildcards when specifying A records which would let you do something like this:

*.mywebsite.com       IN  A would be the IP address of your webserver. The method of actually adding the record will depend on your host.

Doing it like http://mywebsite.com/user would be a lot easier to set up if it's an option.

Then you could just add a .htaccess file that looks like this:

Options +FollowSymLinks

RewriteEngine On
RewriteRule ^([aA-zZ])$  dostuff.php?username=$1

In the above, usernames are limited to the characters a-z

---------- The rewrite rule for grabbing the subdomain would look like this:

RewriteCond %{HTTP_HOST} ^(^.*)\.mywebsite.com
RewriteRule (.*)  dostuff.php?username=%1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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