Getting dynamic subdomains to work

Hey guys!

I am in need of a dynamic subdomain to work. My current URL is

http://DOMAIN.com/con/view?id=1

I have a route that does this




'http://<id:\w+>.DOMAIN.com/' => 'con/view',



I also set up wildcard subdomains in my DNS settings. *.domain.com

Currently when going to my subdomain, it shows the sysdefault error message.

What am I missing to get this working?

I think you should use the redirect settings for the subdomain in the web server level, like in .htaccess in Apache, server in nginx etc

I tried various .htaccess settings as well, but unable to get this to work.

you my try this in .htaccess




RewriteCond %{HTTP_HOST} ^([^.]*)\.domain\.com(.*)$ [NC]

RewriteRule ^(.*)$ http://domain.com/con/view?id=%1/$1 [R=301,L]



This is written on two conditions:

  1. www.domain is redirected to domain. This code should come after that redirection.

  2. Any parameters other than id is not considered in the code above. You may modify as per your conditions.

I have not tested, but think that it should work.