简体   繁体   中英

How to redirect to specific URL?

I have a route for tenants name like that:

example.test/TenantNameHere

And I want to make the default of my domain start with the word "site":

example.test/site

My code:

Route::prefix('{tenantName}')->group(function () {
    Route::get('/', function ($tenantName) {
        return "{$tenantName}";
    });
});


Route::prefix('site')->group(function () {
    Route::get('price', function () {
        return view('welcome');
    });
});

Route::redirect('/', 'site', 301);

The problem that I'm facing with this code now is when I open the domain it redirects me to tenantName route, not to the home page that I made!

How can spreate the route of site from TenantName ?

you just have to register your absolute path ('site') first, and "wildcards" routes after, because everything you put in url line now hit the first tenantName route

try this (reverse the order):

Route::redirect('/', '/site', 301);

Route::prefix('site')->group(function () {
    Route::get('/', function () {
        return view('welcome');
    });
});

Route::prefix('{tenantName}')->group(function () {
    Route::get('/', function ($tenantName) {
        return "{$tenantName}";
    });
});

also change "/site/price" path to "/site", so redirect will find correct route

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM