10

I am using the following code its from the laravel 4 site

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

    Route::get('user/{id}', function($account, $id) {
        // ...
     return Redirect::to('https://www.myapp.com'.'/'.$account);
    });

});

the idea is to redirect subdomain.myapp.com to myapp.com/user/subdomain .what I have is not working any suggestions?sorry I just started with laravel about a month now.

3
  • What is the url you are trying? i'm guessing you should remove the user/{id} and replace it with / and then go to fogsy.myapp.com Commented Jan 24, 2014 at 9:41
  • sometimes I can be so dumb... thanks @MarcvdM Commented Jan 24, 2014 at 9:46
  • Do you solve this @cppit ? Commented Mar 4, 2016 at 5:15

2 Answers 2

14

Remove user/{id} and replace it with / and then use the following url https://accountname.myapp.com and it will redirect to https://www.myapp.com/accountname

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

    Route::get('/', function($account, $id) {
        // ...
        return Redirect::to('https://www.myapp.com'.'/'.$account);
    });

});

Edit the answer to the correct answer

Sign up to request clarification or add additional context in comments.

3 Comments

sorry this is not the answer, the subdomain is not in used if you redirect it directly
I want to use it to redirect from www.mydomain.com to mydomain.com. It is a 301 redirect?
3
Route::group(array('domain' => '{account}.myapp.com'), function() {

    Route::get('/', function($account) {
        // ...
        return Redirect::to('https://www.myapp.com/'.$account);
    });

});

as Marc vd M answer but remove $id from get's closure function.

why use 'https://www.myapp.com'.'/'.$account and not 'https://www.myapp.com/'.$account

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.