Back

redirect from route with segment


syscoid posted 4 months ago

hello..

we problem with route redirect from route to segment domain

problem:

Route::get('/',  function(){
    return redirect('http://www.domain.com', 301);
    //return abort(404);
});

and redirect with segment like this:

Route::get('/',  function(){
    return redirect('http://'.{urlSegment}.'.domain.com/'{urlSegment}', 301);
    //return abort(404);
});

and not fuction.. please given me solution for that.. thanks

Peace-N replied 4 months ago

What is this {urlSegment} what is passing that oh how are you generating that ?

syscoid replied 4 months ago

{urlSegment} from controller, like this:

Route::get('{urlSegment}/commercial', '[email protected]')->name('commercial');

if we running like this, not fuction:

Route::get('/',  function(){
    return redirect('http://'.{urlSegment}.'.domain.com/'{urlSegment}', 301);
});

can given me solution?

Peace-N replied 4 months ago

Update to the following and give me the result .

Route::get('/',  function(){
    dd('http://'.{urlSegment}.'.domain.com/'{urlSegment}'); //die and dump here and tell me the results
    return redirect('http://'.{urlSegment}.'.domain.com/'{urlSegment}', 301);
});
syscoid replied 4 months ago

i try on route/web.php like this:

Route::get('/',  function(){
    dd('http://'.{urlSegment}.'.domain.com/'{urlSegment}'); //die and dump here and tell me the results
    return redirect('http://'.{urlSegment}.'.domain.com/'{urlSegment}', 301);
});

and syntax error, unexpected '{' on:

dd('http://'.{urlSegment}.'.domain.com/'{urlSegment}'); //die and dump here and tell me the results
Peace-N replied 4 months ago

So you see that's where the issue is :

This should be, double check your quotes:

'http://' . "{urlSegment}" . '.domain.com/' . "{urlSegment}"
syscoid replied 4 months ago

its the same not function, we added like this on route/web.php:

return redirect('http://'."{urlSegment}".'.domain.com/'."{urlSegment}", 301);

and see on browser like this:

http://%7Burlsegment1%7D.domain.com/%7BurlSegment1%7D

Sign in to participate in this thread!



We'd like to thank these amazing companies for supporting us