subdomain api with similar path with web.php hi! i have a route api.domain.tld/image/24 in api.php and domain.tld/image/24 in web.php.
when i access api.domain.tld/image/24 it redirects to web. how can i access the api without redirection?
i have wildcard A host record pointing to the same ip address with the root domain.
// routes/api.php
Route::group(['domain' => '{subdomain}.domain.tld'], function() {
Route::get('image', function($subdomain) {
if($subdomain === 'api') {
Route::get('{id}/{resolution?}', 'API\TestController@test');
}
});
});
// routes/web.php
Route::get('image/{id}/{slug?}','TestController@test')->name('image-details');
also, Route::prefix('api') removed in RouteServiceProvider.php
@jaeyson I don’t really understand your routing. You have Route::get inside another Route::get. That doesn’t really make sense and probably isn’t a valid route.
Just set the domain in your API route group and then place your API routes inside there:
Route::domain('api.domain.tld')->group(function () {
Route::get('/', function () {
return response()->json(['message' => 'Hello, world.']);
});
});
yes i was doing that exactly. problem is i had similar paths with
when i visit api.domain.tld/test/3 it always redirects to domain.tld/test/3. is it because i had similar route path?
Please sign in or create an account to participate in this conversation.