0

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.

2 Answers 2

1

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.

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

5 Comments

thankyou for you answer but in my case in example.com there is another application running and something.com is its subdomain. i want to know can we change the whole url name from laravel. like in my case for above route 'test' there will always be in url subdomainname/test,can i change this url to myprofile/test and for other routes it is fine to have route like subdomainname/login etc.
Route::group(['prefix'=>'subdomainname'],function(){ Route::get('test','ProfileController@test'); });
I think you could do something like this put on group with a prefix.
Inside this you could add the login routes and other routes that you like.
I'm sorry.! Ohh I got it! see the next answer.. I agree with the wunch solution!
0

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');
});

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.