poupette
poupette

Reputation: 61

Laravel redirect to another subdomain

I’d like to redirect my subdomain test.example.com to another sub-domain www.example.com. I added the code below in my routes.php but it doesn't seem to work.

Route::group(array('domain' => '{test}.example.com'), function() {
     Route::get('/', function($test) {
         return Redirect::to('http://www.example.com');
     });
});

When I type test.example.com in my browser I'm not being redirected to www.example.com. Does someone have any suggestions how I can fix this?

Upvotes: 1

Views: 3095

Answers (2)

poupette
poupette

Reputation: 61

I figured out that I had a problem with the settings of my DNS server. I was using a CNAME record for my subdomain "test.example.com" instead of using a URL record, 301 permanently moved. So, I removed my CNAME record and replaced it with a URL record, and everything seems now to be working fine. Thanks @everon and @Set Kyar Wa Lar for helping

Upvotes: 1

Everon
Everon

Reputation: 3879

Haven't played with sub domain routes myself just yet but try this

Route::group(array('domain' => '{test}.example.com', 'before' => 'tomaindomain');


Route::filter('tomaindomain', function()
{
    return Redirect::to('SomeDomain.com');
});

I've only applied a route filter to the entire subdomain, you could remove the wildcard or check $test is equal to "test" before redirecting. I figured you could just return a Redirect request inside an if statement from within the Route group but I haven't tested it.

Upvotes: 1

Related Questions