nielsv nielsv - 3 months ago 29
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 domain.com My .htaccess file (in public_html folder) is like this:

<IfModule mod_rewrite.c>
RewriteEngine On

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


There are the following routes:


  • api/licenseplate

  • api/calendar

  • auth/login

  • admin/settings

  • admin/appointments

  • appointment

  • ...



So an example of a URL is http://domain.com/appointment.

Now I would like to have a wordpress website on domain.com. So when you go to domain.com 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

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

/var
     /www
         /laravel
             /public
                 /wp #(symlink to -> /var/www/wordpress/public_html)
                 index.php
                 .htaccess
         /wordpress
             /public_html
                 index.php
                 .htaccess

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
    </IfModule>

    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]

</IfModule>

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]
</IfModule>

# END WordPress
Comments