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

IND1201259H8's avatar

Route::domain not working in shared hosting with cPanel

Hello! I have a laravel site and I want it to work with subdomains to like this:

domain.com -> Route principal subdomain1.domain.com -> agency1 subdomain2.domain.com -> agency2

all the subdomain are static and no dynamic.

I'm trying to use Route::domain like this

Route::domain('domain.com')->group(function () {
    Route::get('/', function () {
         return view('welcome');
    });
    
    Route::get('/testing', function() {
	    return view('home');
    });
});

and

Route::domain('agency.domain.com')->group(function () {
    Route::get('/', function () {
         return view('home');
    });
});

On local works perfectly but when I try this on my shared hosting this does not work I add the subdomain in the Subdomain section of cPanel but I get a 403 error.

Does anyone have try to do this on a shared hosting?

0 likes
7 replies
automica's avatar

Can you explain what directories your sub domains are pointing to?

They should all be pointing to the same Document Root as your primary domain, and its /public folder.

Sinnbeck's avatar

Are you sure you actually hit laravel? Might be your server provider denying the request

Be sure they both point to the right ip and that the server is set up to accept all domains

IND1201259H8's avatar

The subdomain folders are created in public_html/subdomain, my structure is like this:

/home/user/laravel

/home/user/public_html -> the public folder for laravel

/home/user/public_html/subdomain1 -> this is how cPanel create the folder for subdomains

/home/user/public_html/subdomain2

siangboon's avatar

as what i understand, when you create a subdomain in cpanel, it will function as standalone hosting... which mean there is a documentroot at that subdomain itself handle all the request to that subdomain...

try create the "subdomains" dns record point to the same ip address without the subdomain in cpanel first...

automica's avatar
automica
Best Answer
Level 54

@ind1201259h8 on your interface in cPanel where you have your subdomains listed you should have a table grid

with the following headings:

Subdomains Document Root ▾ Redirection Actions

if you look down the Document Root Column you should have a little icon that looks like a house at the start and a pencil at the end. Click on the pencil and it will let you change the document root.

You need to change the document root of your 2 subdomains to point to the same folder as your primary domain

eg

/home/user/public_html/public

you want to checkout your whole project to /home/user/public_html/

you will also need to ask your ISP to change your primary domain webroot to /home/user/public_html/public too

IND1201259H8's avatar

Ok, would try to do that and let you if this work, thanks.

Wooow, well thank you so much for the help, that was the thing that I needed to do. It did work out that way.

Thanks atomica, siangboon and Sinnbeck for taking the time to help me.

1 like

Please or to participate in this conversation.