To achieve the setup where your Laravel application serves different content on the main domain (www.company.com) and the subdomain (app.company.com), you can follow these steps:
-
DNS Configuration:
- Ensure that both
www.company.comandapp.company.comare pointing to your server's IP address. This is typically managed through your domain registrar's DNS settings.
- Ensure that both
-
Laravel Forge Configuration:
- In Laravel Forge, you will need to set up two separate sites for your application: one for the main domain and one for the subdomain.
- Go to your server in Laravel Forge and create a new site for
www.company.com. During the setup, you can specify the directory where the corporate site pages are located. This could be the same directory as your Laravel app if you are using route-based separation.
-
Nginx Configuration:
- Laravel Forge will automatically handle the Nginx configuration for you when you set up the sites. However, you might want to ensure that the root directory for each site is correctly set.
- For
www.company.com, you might want to point to the public directory of your Laravel app if you are serving the corporate pages through Laravel routes.
-
Route Configuration in Laravel:
- In your
routes/web.php, you can define routes that serve different content based on the domain. Use theRequestfacade to check the host and serve the appropriate content.
use Illuminate\Support\Facades\Route; use Illuminate\Http\Request; Route::group(['domain' => 'www.company.com'], function () { Route::get('/', function () { return view('corporate.home'); }); // Add other corporate site routes here }); Route::group(['domain' => 'app.company.com'], function () { Route::get('/', function () { return view('app.dashboard'); }); // Add other application routes here }); - In your
-
SSL Certificates:
- Use Laravel Forge to provision SSL certificates for both
www.company.comandapp.company.comusing Let's Encrypt. This will ensure that both domains are served over HTTPS.
- Use Laravel Forge to provision SSL certificates for both
-
Testing:
- After setting everything up, thoroughly test both domains to ensure that they are serving the correct content and that there are no issues with routing or SSL.
By following these steps, you can serve different content on your main domain and subdomain without affecting the existing application functionality. Always ensure you have backups and test in a staging environment if possible before making changes to production.