nielsv nielsv - 1 year ago 103
HTTP Question

Laravel project next to Wordpress project (in public_html folder)

I have a Laravel project in my public_html folder. The domain is for example My .htaccess file (in public_html folder) is like this:

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteRule ^(.*)$ public/$1 [L]

There are the following routes:

  • api/licenseplate

  • api/calendar

  • auth/login

  • admin/settings

  • admin/appointments

  • appointment

  • ...

So an example of a URL is

Now I would like to have a wordpress website on So when you go to you see the wordpress website. But I also want to have the urls like /appointment of my laravel project.

What's the easiest and cleanest way to do this?

mnv mnv
Answer Source

You can create symlink to Wordpress public directory in Laravel folder. For example, wp:

                 /wp #(symlink to -> /var/www/wordpress/public_html)

And describe Laravel routes in .htaccess. Example of code of /var/www/laravel/public/.htaccess:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews

    RewriteEngine On

    RewriteCond %{ENV:REDIRECT_FINISH} .
    RewriteRule ^ - [L]

    # Laravel

    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteCond %{REQUEST_FILENAME} !.*\.php$
    RewriteRule ^(.*)$ $1 [E=FINISH:1,L]

    RewriteCond %{REQUEST_URI} ^/(api/licenseplate)(\?.*|$) [OR]
    RewriteCond %{REQUEST_URI} ^/(api/calendar)(\?.*|$) [OR]
    RewriteCond %{REQUEST_URI} ^/(admin/settings)(\?.*|$) [OR]
    RewriteCond %{REQUEST_URI} ^/(admin/appointments)(\?.*|$) [OR]
    RewriteCond %{REQUEST_URI} ^/(appointment)(\?.*|$) [OR]
    RewriteCond %{REQUEST_URI} ^/(auth/login)(\?.*|$)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php [E=FINISH:1,L]

    # Wordpress

    RewriteCond %{REQUEST_URI} !^/wp
    RewriteRule ^(.*)$ /wp/$1 [E=FINISH:1,L]


Code of /var/www/wordpress/public_html/.htaccess (just copy of your wordpress .htaccess):

# BEGIN WordPress

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]

# END WordPress
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download