【发布时间】:2017-03-23 02:11:25
【问题描述】:
Route::get('test','ProfileController@test'); 我有上面的路线,在 url 中点击这条路线时,我看到 www.example.com/test, 是否可以仅针对此特定路由使用 laravel 路由将 url 更改为 something.com/test。
【问题讨论】:
标签: laravel
Route::get('test','ProfileController@test'); 我有上面的路线,在 url 中点击这条路线时,我看到 www.example.com/test, 是否可以仅针对此特定路由使用 laravel 路由将 url 更改为 something.com/test。
【问题讨论】:
标签: laravel
example.com是你的域名,那么你需要购买something.com
那么你需要配置 something.com 指向你的服务器,该服务器托管你的 laravel 应用程序。然后你可以做某事.com/test。
记住,
example.com -> 翻译为 XXX.XXX.XXX.XXX IP
something.com -> 需要翻译成同一个XXX.XXX.XXX.XXX IP
因为example.com 是主机部分,/test 是您应用的路径。
【讨论】:
Route::group(['prefix'=>'subdomainname'],function(){ Route::get('test','ProfileController@test'); });
如果不实际重定向到该新域,则无法更改 url 的可见域部分。 (这样做会带来严重的安全风险。)
如果你想重定向到其他域(假设它存在),你可以这样做:
// Redirect a route to another URL (note the use of the http://)
Route::get('/test', function() {
return redirect('http://something.com/test');
});
但是,如果目标是运行相同应用程序的当前域的子域或别名,那么您可以使用subdomain routing。我喜欢使用命名路由:
// 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');
});
【讨论】: