My website runs with the following virtual host configuration:
<IfModule mod_ssl.c>
<VirtualHost *:443>
DocumentRoot /home/myuser/MyDomain/src
ServerName MyDomain
ServerAlias www.MyDomain
ErrorLog /home/myuser/logs/apache/MyDomain-error_log
CustomLog /home/myuser/logs/apache/MyDomain-access_log common
DirectoryIndex index.php
<Directory /home/myuser/MyDomain/src>
Options -Indexes +FollowSymLinks
AllowOverride None
Require all granted
AddOutputFilterByType DEFLATE text/html text/plain text/xml
</Directory>
#LogLevel alert rewrite:trace6
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteRule ^/api/media/(.*) /data/$1 [L]
RewriteRule ^/api/v1/* /api/v1/index.php [L]
RewriteRule ^/api/cdn/v1/* /api/cdn/v1/index.php [L]
RewriteRule ^/assets/(.*) /website/v1/content/assets/$1 [L]
RewriteRule ^/css/(.*) /website/v1/content/css/$1 [L]
RewriteRule ^/js/(.*) /website/v1/content/js/$1 [L]
RewriteRule ^/fonts/(.*) /website/v1/content/fonts/$1 [L]
RewriteRule ^/\.well-known/acme-challenge/(.*)$ /.well-known/acme-challenge/$1 [L]
RewriteRule ^/* /website/v1/index.php [L]
#sslstuff
</VirtualHost>
</IfModule>
I am migrating to Laravel and would like to deploy Laravel alongside live website on /v2
path. Laravel app is in the /website/v2/p2
folder, so I added another rewrite for all urls that start with /v2
. This is my current conf file (I only added a single rewrite):
<IfModule mod_ssl.c>
<VirtualHost *:443>
DocumentRoot /home/myuser/MyDomain/src
ServerName MyDomain
ServerAlias www.MyDomain
ErrorLog /home/myuser/logs/apache/MyDomain-error_log
CustomLog /home/myuser/logs/apache/MyDomain-access_log common
DirectoryIndex index.php
<Directory /home/myuser/MyDomain/src>
Options -Indexes +FollowSymLinks
AllowOverride None
Require all granted
AddOutputFilterByType DEFLATE text/html text/plain text/xml
</Directory>
#LogLevel alert rewrite:trace6
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteRule ^/v2/(.*) /website/v2/p2/public/index.php [L] # this is new
RewriteRule ^/api/media/(.*) /data/$1 [L]
RewriteRule ^/api/v1/* /api/v1/index.php [L]
RewriteRule ^/api/cdn/v1/* /api/cdn/v1/index.php [L]
RewriteRule ^/assets/(.*) /website/v1/content/assets/$1 [L]
RewriteRule ^/css/(.*) /website/v1/content/css/$1 [L]
RewriteRule ^/js/(.*) /website/v1/content/js/$1 [L]
RewriteRule ^/fonts/(.*) /website/v1/content/fonts/$1 [L]
RewriteRule ^/\.well-known/acme-challenge/(.*)$ /.well-known/acme-challenge/$1 [L]
RewriteRule ^/* /website/v1/index.php [L]
#sslstuff
</VirtualHost>
</IfModule>
Visiting /v2/index.php
now works. Unfortunately visiting /v2
alone returns 404. Defining a new route in routes/web.php
Route::get('/newroute', function () {
return "It works, lol";
});
and visiting it also returns 404 error.
What is the correct way of deploying Laravel alongside live app?
UPDATE:
Rewrite log correctly resolves to Laravels index.php
as shown here:
init rewrite engine with requested uri /v2
applying pattern '^/v2(/.*)?$' to uri '/v2'
RewriteCond: input='/v2' pattern='!-d' => matched
RewriteCond: input='/v2' pattern='!-f' => matched
rewrite '/v2' -> '/website/v2/p2/public/index.php'
setting lastsub to rule with output /website/v2/p2/public/index.php
local path result: /website/v2/p2/public/index.php
prefixed with document_root to /home/myuser/MyDomain/src/website/v2/p2/public/index.php
go-ahead with /home/myuser/MyDomain/src/website/v2/p2/public/index.php [OK]
It seems that 404 issue stems from how Laravel is handling paths