I’m trying to redirect a subdomain user to his profile.
For example: If user requested user.example.com
he gets redirected to example.com/user
I searched a lot, and most answers were old and didn’t work.
Things I have done:
- Created A record with *.example.com.
- Enabled wildcard redirect to example.com (I actually don’t know if
this is needed) some Stack Overflow answer provided that. - Created subdomain in my hosting like *.example.com (but this caused
all my subdomains get redirected to the main landing page, which is
example.com) some Stack Overflow answers provided that. - In my larave project routes.
Route::domain('{name}'.'example.com')->group(function () {
Route::get('/{name}', 'usersController@profile');
});
Route::group(['domain' => '{account}.example.com'], function () {
Route::get('/{name}', 'usersController@profile');
});
I’m really lost between old Stack Overflow answers and PHP hard code. All I want is simple. If user requested user.example.com he gets redirected to his profile example.com/user then he can navigate normally like no need for subdomain later.
I don’t know what I’m missing or doing wrong!
2
Answers
Glad to know this this worked out for you. Here i am dropping a formatted answer of it. Can help others.
This worked for me.