Reputation: 243
Route::get('test','ProfileController@test'); I have above route,while hitting this route in url i see www.example.com/test, Is it possible to change the url to something.com/test using laravel routing only for this specific route.
Upvotes: 0
Views: 5776
Reputation: 1092
You cannot change the visible domain part of the url without actually redirecting to that new domain. (Doing so would be a serious security risk.)
If you want to redirect to that other domain (assuming it exists), you can do:
// Redirect a route to another URL (note the use of the http://)
Route::get('/test', function() {
return redirect('http://something.com/test');
});
However, if the target is a subdomain or alias of the current domain which is running the same application, then you can do subdomain routing. I like to use named routes:
// Define the route on the subdomain
Route::group(['domain' => 'subdomain.example.com', function() {
Route::get('/test', ['as' -> 'subdomain.test', 'uses' => 'ProfileController@test']);
});
// Redirect a route on the main domain to the subdomain
Route::get('/test', function() {
return redirect()->route('subdomain.test');
});
Upvotes: 0
Reputation: 11
example.com
is your domain, then you need to buy something.com
then you need to configure something.com
that point to your sever that is hosting your laravel application. Then you could do something.com/test.
Remember,
example.com -> translate like XXX.XXX.XXX.XXX IP
something.com -> need to be translated to the same XXX.XXX.XXX.XXX IP
Because example.com
is the host part and /test
is the path of your app.
Upvotes: 1