1

I'm looking Dayle Rees site consern to routing and I'm unable to implement the following subdomain routing.

Route::group(array('domain' => 'another.url.dev'), function()
{
    return 'Hello';
});

I've set a virtual host called url.dev which point to \var\www\url.dev\public which works just fine.

What is next? How can I access another.url.dev ? I've tried to access it directly as http://another.url.dev but it could not be found.

Do I miss something? Do I have to configure my server,hosts etc?

Addendum

My goal is to implement something like this

Route::group(array('domain' => '{account}.myapp.com'), function()
{

    Route::get('user/{id}', function($account, $id)
    {
        //
    });

});
Laurence
  • 58,936
  • 21
  • 171
  • 212
giannis christofakis
  • 8,201
  • 4
  • 54
  • 65
  • What happens when you access it, a 404? Have you tried creating a vhost for it and add an A record for it? I don't know anything about L4 subdomain routing but that's just my 2 cents. – Jared Eitnier Jan 28 '14 at 01:12

1 Answers1

3

You need to have a wildcard redirect for subdomains setup on both your development environment and your production environment.

Without them, requests to "http://somerandomsubdomain.example.com" will never even get routed to you application. Laravel won't even get a chance to deal with it.


EDIT: Sorry, I was leaving work when I left that incomplete answer.

Completely separate from your Laravel app, you will need a way for the subdomains to be mapped to an IP address. You will have to set this up on both your development machine(s) and your production server(s).

In production, it's pretty easy. You have to add a DNS entry to create an CNAME record. so that *.example.com just points to example.com. Your web host or DNS provider may have to do this for you, if you don't have control or access to your DNS server.

On your development machines, it can be a little tougher. If you are using a local DNS server, or have dnsmasq installed or available (maybe on your router) you will create a CNAME record just like you would in production.

However, many development environments rely on customized hosts files, and you can't to wildcard redirects there. However, if you know what your subdomains will be ahead of time, you can just add the following to /etc/hosts (OSX or *nix like systems) or %SystemRoot%\system32\drivers\etc\hosts in Windows:

127.0.0.1 example.dev
127.0.0.1 sub1.example.dev
127.0.0.1 sub2.example.dev

If you give a little more info about your development and production environments, I might be able to help more.

In the meantime, this answer might help a bit too: https://stackoverflow.com/a/79811/388682

Community
  • 1
  • 1
TunaMaxx
  • 1,782
  • 12
  • 18
  • Please be more specific. Do I have to change my `.htaccess` file, my `url.dev.conf` in my `/available-sites/`? Can you give me a reference/link/example preferable a solution? – giannis christofakis Jan 28 '14 at 07:35
  • Sorry. I was in the process of leaving work when I wrote that. I've expanded on the answer a bit. – TunaMaxx Jan 28 '14 at 17:22