htaccess – laravel with WordPress

I’m trying to get wordpress and laravel to run side-by-side and hitting a small issue.

Here’s my code

Read More
# BEGIN Laravel
<IfModule mod_rewrite.c>
    Options -MultiViews
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^/?admin/?.*$ index.php [L]
</IfModule>
# END Laravel

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

the wordpress pages work, apart from the homepage and the admin pages work (laravel), apart from if there is no ‘/’ at the end.

Any ideas?

regards

Related posts

Leave a Reply

2 comments

  1. ‘Rewrite’ means “treat the URL as if it matches this filename”. The file run can still tell what the original URL was, so it knows what to show.

    The code

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    

    means that if the file with the specified name doesn’t exist, or the directory in the browser doesn’t exist then proceed to the rewrite rule below.

    The first rule you have is ‘send anything that has /admin/ in it to index.php’ – presumably Laravel.

    The second rule you have is ‘send anything to wp-index.php’ – presumably WordPress.

    Servers are typically set up to direct / to index.php, and the line

    RewriteRule ^index.php$ - [L]
    

    means “don’t rewrite index.php, and stop”, so that’s why the “home page” is going to Laravel.

    Comment that line out (add a # to the beginning) and see if that makes your home page go to WordPress.

    Also, /admin won’t direct to Laravel because it doesn’t match the rule (which is based on /admin/). If you want /admin to work, take out the / from the first rule.