Username as subdomain on laravel

后端 未结 4 1449
滥情空心
滥情空心 2021-01-30 07:47

I\'ve set up a wildcard subdomain *.domain.com & i\'m using the following .htaccess:

Options +FollowSymLinks
RewriteEngine On
RewriteBase /

RewriteCond %{HT         


        
4条回答
  •  故里飘歌
    2021-01-30 08:14

    While I can't say what the full solution would be in your case, I would start with the SERVER_NAME value from the request (PHP: $_SERVER['SERVER_NAME']) such as:

    $username = str_replace('.domain.com', '', Request::server('SERVER_NAME'));
    

    Make sure you additionally clean/sanitize the username, and from there you can lookup the user from the username. Something like:

    $user = User::where('username', '=', $username)->first();
    

    Somewhere in the routes file you could conditionally define a route if the SERVER_NAME isn't www.domain.com, or domain.com, though I'm sure others can come up with a much more eloquent way for this part...

提交回复
热议问题