Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

sorcjc's avatar

Link a Laravel app with two different subdomains

Please, let me describe my situation:

  • Initially I had a blog on my domain: myweb.com (powered by Jekyll)
  • After that I have created a Laravel app in a Digital Ocean droplet, and associate it with a subdomain: tutorials.myweb.com
  • Now I want to create a new functionality on my Laravel app that allow users to create galleries.

The problem is, the URL for the galleries will be: tutorials.myweb.com/galleries But the galleries are not associated with the tutorials directly.

I want to use galleries.myweb.com, but associate this subdomian with tutorials.myweb.com/galleries, because I want to use the same Laravel app (to share the same users).

Is it possible? How I can achieve it? Please give me ideas.

Thank you in advance.

0 likes
2 replies
Thyrosis's avatar

To be honest, I don't think you can make this work if you use any kind of sessions.

Sessions are (sub)domain based, so a logged in user for tutorials.myweb.com will not be logged in on galleries.myweb.com.

If sessions are not an issue, you can set galleries.myweb.com as a server-alias for tutorials.myweb.com. Out of the box, this will bring visitors to galleries.myweb.com to the same page as tutorials.myweb.com.

From there, you can force a redirect with an .htaccess file, which should be something like this:

RewriteEngine On 
Options +FollowSymlinks 
RewriteBase / 
RewriteCond %{HTTP_HOST} galleries.myweb.com 
RewriteCond %{REQUEST_URI} !^/galleries/? 
RewriteRule ^(.*)$ galleries/$1 [L] 

I'm not familiar with Digital Ocean so I don't know how to set server aliasses, maybe somebody else or the DO support can help you with that.

1 like
sorcjc's avatar

@Thyrosis Thank you for your help.

Finally I have associated both subdomains with the same droplet, and manage the routes in the same Laravel app.

I didn't know than that was possible.

The routes in Laravel are awesome.

Please or to participate in this conversation.