1

I want to have a Wordpress and a Laravel under the same domain, so I can keep Wordpress and Laravel session always up and have Single Sign On between both. This objetive was achieved, but now I want to move laravel to another folder for security and define an Apache Alias with a sublocation. This is working too.

But the friendly URLs in laravel stoped to working. I think that I need make some change on .htaccess. I leave how I have my Apache2 config right now.

<VirtualHost *:80>
        ServerName einflamatoria.inventeddomain.com

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/einflamatoria-foro-wp

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        Alias /educaforo-master /var/www/educaforo-master/public
        <Location /educaforo-master>
                Options -Indexes +FollowSymLinks +MultiViews
                AllowOverride all
                Require all granted
        </Location>
</VirtualHost>

And Laravel .htaccess right now is

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

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ ./index.php?$1 [L,QSA]
</IfModule>

With this configuration if I want to go to

einflamatoria.inventeddomain.com/educaforo-master/forums gives me a 404

but if I go to einflamatoria.inventeddomain.com/educaforo-master/index.php/forums works fine, but I need that it works without index.php.

Zarovich
  • 13
  • 4
  • Can you check the mode status in your system by command **a2enmod status** ? – Rajdip Chauhan Sep 03 '19 at 13:05
  • You probably need to specify a RewriteBase here in combination with the Alias, see https://httpd.apache.org/docs/2.4/mod/mod_rewrite.html#rewritebase – misorude Sep 03 '19 at 14:12
  • So `http://einflamatoria.inventeddomain.com/educaforo-master/forums` to `http://einflamatoria.inventeddomain.com/./index.php?educaforo-master/forums` is that the desired URI? – ficuscr Sep 03 '19 at 17:45
  • @ficuscr No, it isn't. Because einflamatoria.inventeddomain.com has the index.php. educaforo-master is a sublocation targeting another directory with a laravel installation. Actually educaforo-master points to /var/www/educaforo-master/public with a Alias for educaforo-master, and the main virtualhost for einflamatoria.inveteddomain.com points to /var/www/einflamatoria-wp. But Apache finds without problem both webs. The problem is with laravel .htaccess which is like isn't readed by Apache. – Zarovich Sep 04 '19 at 06:20
  • Oh sorry, checked the a2enmod status en mod alias and mod rewrite are both active. @RajdipChauhan. – Zarovich Sep 04 '19 at 06:25
  • I've tried adding RewriteBase directive and didn't work. But i'm not sure if i'm understanding how works exactly, because maybe I should assume that Apache will ignore the laravel htaccess as its pointed by an Alias and configured by Location directive? and I should add Laravel .htaccess rules to main Wordpress .htaccess rules under a RewriteBase maybe?. @misorude – Zarovich Sep 04 '19 at 06:27
  • Might want to use an [.htaccess tester](https://htaccess.madewithlove.be/) then. You can also turn on more verbose logging that is helpful in [debugging rewrites](https://stackoverflow.com/questions/9632852/how-to-debug-apache-mod-rewrite). When you start talking about wordpress and laravel rules you totally lost me. That means nothing to me. – ficuscr Sep 04 '19 at 14:54
  • Tried to put same htaccess rules at Location in Apache config file for this VirtualHost and worked fine. – Zarovich Sep 05 '19 at 11:53
  • Sorry @ficuscr, finally I did it (just read the notification now), by just writing specific rules I needed in sublocation definition instead of .htaccess. And everything started to work. And it's a weird thing, since I was just doing to work Laravel in a sublocation to work as it was part of Wordpress, loading in Laravel Wordpress engine and make a smooth integration in order to make user feel that he's always in same page. And finally everything worked fine. Btw, thx all for your comments and help. – Zarovich Oct 07 '19 at 09:05

0 Answers0