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

AlunR's avatar
Level 3

Adding Laravel app in a subfolder to WordPress

We have a customer with an existing Wordpress site they are happy with but they would like the core function replace which sits in a folder called /directory

Is it possible to send all traffic to /directory to a different .php file? Eg rename the Laravel index.php to laravel-index.php so all Wordpress requests are handled by index.php still?

We could stick it on a sub domain but it would be more seamless this way.

0 likes
10 replies
Snapey's avatar

laravel is not designed to run in a folder. You may get out to work or you may have problems

Oleg_Knyazev's avatar

Why, though? If the virtual hosts and proxies are set up properly on Nginx or Apache, Laravel would be served the same. It's basically same thing as setting up Nuxt with Laravel as API served via /api route instead of a subomain.

AlunR's avatar
Level 3

Laravel won’t be in a folder. We’ll just be routing only /directory requests to the Laravel app. Everything else will be handled by Wordpress

Snapey's avatar

it's got nothing to do with virtual hosts or proxies

Oleg_Knyazev's avatar

If I assumed correctly, the author wants to keep the main website running on Wordpress, but serve a Laravel app on the same domain. Then they can certainly put wordpress on one directory and laravel in the other directory, set up hosts for different locations and root folders, and run it side by side.

Otherwise, the issue hasn't been described clearly and I'm assuming wrong.

1 like
Snapey's avatar

you missed the bit where he says he knows it could be done in a sub domain

Oleg_Knyazev's avatar

No I did not, and I'm not talking about using a subdomain. I'm talking about placing wordpress in one directory, the Laravel app in another, and then routing the traffic via server configuration so the requests to mysite.com would lead to a wordpress site, and the laravel app would be served when the user goes to, say, mysite.com/control-panel. It's all done by setting up vhosts in Nginx or Apache, basically. The main host uses / as a location parameter and the wordpress public directory as root, and Laravel app's host utilizes, say, /control-panel as a location and point to its public directory. If I'm not mistaken, it's done under the same vhost even, only with specifiying the different location blocks.

AlunR's avatar
Level 3

More simply than this we can simply preserve the Laravel htaccess file and add a line to grab all the non /control-panel requests and point them at the Wordpress index.php instead of the Laravel index.php

AlunR's avatar
Level 3

I’m saying I know it COULD be done using directory.mydomain.com but I would prefer my domain.com/directory instead

Please or to participate in this conversation.