title: Laravel 5.8 use subdomain as API endpoint beside domain.com/api
body: <p>I have a production server with some API's endpoints. I just want to make a more pretty system moving all API calls from <code>domain.com/api/v1/xxxxxx</code> to a subdomain like <code>api.domain.com/v1/xxxxxx</code></p>
  
  <p>By now, I just create the subdomain at cPanel: api.domain.com
  then point that subdomain to the <code>public_html</code> folder of laravel (I did the trick for <code>public -&gt; public_html</code> rename )</p>
  
  <p>Then add the route mapping domain in api.php:</p>
  
  <pre><code>//SubDomain Mapping
  Route::group(['domain' =&gt; 'api.bachecubano.com'], function () {
      Route::group(['prefix' =&gt; 'v1'], function () {
          Route::get('categories', 'Api\AdController@get_categories')-&gt;name('api_get_categories');
      });
  });
  </code></pre>
  
  <p>And try it at <code>api.domain.com/v1/xxx</code> but give me error. So the working solution is <code>api.domain.com/api/v1/xxx</code></p>
  
  <p>But that its too ugly, I need to remove the second <code>/api/</code> url parameter.</p>
  
  <p>How do I tho this?</p>
  
  <p>PS: Put the subdomain mapping to <code>public_html/api</code>, but that obviously crash with error 500.</p>
  
  <p>My mind says to me that the solution might be in .htaccess file, but In don't know much about it.</p>
  
  <p>Thanks</p>