14

I am trying to host a WordPress site inside a Laravel(5.1) project. I have the following structure (stripped down some)

├── app
├── config
├── public
│   ├── index.php
│   ├── wordpress -> ../wordpress
│   └── .htaccess
├── resources
├── storage
├── vendor
└── wordpress
    ├── index.php
    ├── wp-admin
    ├── wp-config.php
    ├── wp-includes
    └── .htaccess

The vhost document root is public.

The Wordpress should catch everything that falls through the .htaccess. But for example /login should go to laravel. When my project grows i intend to add more rules to catch requests for Laravel. I have the following .htaccess file in /public:

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

    RewriteEngine On

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule "^/login" "index.php" [L]

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule "^(.*)$" "wordpress/$1" [L]
</IfModule>

But when i make the request to /login i still end up with the wordpress page. Here is a part of the log:

 add path info postfix: /var/www/public/login -> /var/www/public/login/
 strip per-dir prefix: /var/www/public/login/ -> login/
 applying pattern '^/login' to uri 'login/'
 add path info postfix: /var/www/public/login -> /var/www/public/login/
 strip per-dir prefix: /var/www/public/login/ -> login/
 applying pattern '^(.*)$' to uri 'login/'
 RewriteCond: input='/var/www/public/login' pattern='!-d' => matched
 RewriteCond: input='/var/www/public/login' pattern='!-f' => matched
 rewrite 'login/' -> 'wordpress/login/'
 add per-dir prefix: wordpress/login/ -> /var/www/public/wordpress/login/
 strip document_root prefix: /var/www/public/wordpress/login/ -> /wordpress/login/
 internal redirect with /wordpress/login/ [INTERNAL REDIRECT]

It seems like the rewriting does not stop at the [L] flag.

Niek de Gooijer
  • 654
  • 1
  • 9
  • 18

3 Answers3

6

Ended up asking the same question on ServerFault. There i got the answer. Linking it here for refference:

https://serverfault.com/questions/739728/laravel-and-wordpress-on-same-server-domain

Community
  • 1
  • 1
Niek de Gooijer
  • 654
  • 1
  • 9
  • 18
3

As asked in the comment, here is the response:

As you can see in your logs the first condition didn't match:

applying pattern '^/login' to uri 'login/'

login/ doesn't start with /

So you need to change your rule to

RewriteRule "^login/" "index.php" [L]
Froggiz
  • 683
  • 8
  • 13
1

It's possible to add a rewrite condition to the default Laravel .htaccess file that will allow all requests to a subdirectory ( /wordpress ) to be ignored by Laravel.

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

    RewriteEngine On

    # Ignore Wordpress directory
    RewriteCond $1 !^(wordpress)

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>
Jeemusu
  • 10,415
  • 3
  • 42
  • 64
  • That would not help my case. Because the url should not contain /wordpress. For example {url}/login and {url}/portal should be handled by laravel while {url}/info and {url}/blog should be handled by Wordpress. – Niek de Gooijer Dec 03 '15 at 07:13