I'm trying to setup a Laravel app in a subfolder of a WordPress website.
The idea is that when a request goes to example.com/{anything}, the WordPress website will respond but if the request is made on example.com/get-started/*, then the Laravel website will handle the request.
I have found a few similar questions online but none of them is working for me. The recent I have tried is this one from laracasts.
My root htaccess file is
# Block the include-only files.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^wp-admin/includes/ - [F,L]
RewriteRule !^wp-includes/ - [S=3]
RewriteRule ^wp-includes/[^/]+\.php$ - [F,L]
RewriteRule ^wp-includes/js/tinymce/langs/.+\.php - [F,L]
RewriteRule ^wp-includes/theme-compat/ - [F,L]
</IfModule>
# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_URI} !^/get-started [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
My htaccess from 'get-started' folder is
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
htaccess from 'get-started/public' folder 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]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
When I open example.com/get-started, it displayes laravel's default 404 page which tells me that the redirection is working but the laravel app doesn't have a corresponding route.
So I give you my web.php file
Route::redirect('/', '/step/1')->name('home');
Route::match(['GET', 'POST'], '/1', [\App\Http\Controllers\HomeController::class, 'step1'])->name('1');
Route::match(['GET', 'POST'], '/2', [\App\Http\Controllers\HomeController::class, 'step2'])->name('2');
Route::match(['GET', 'POST'], '/3', [\App\Http\Controllers\HomeController::class, 'step3'])->name('3');
I'm using this preset from Laravel.
.htaccessfile at/get-started/public/.htaccess? Please update your question to include the contents of this file also..htaccessfile shipped with laravel that's why I didn't upload it initially but I have edited my question to include it as well..htaccessfiles look OK. There are a few things that could be tidied up, but nothing that would change the working. This looks like a Laravel routing issue. However, I'm not sure what you mean by "I can prefix all the URLs but then the assets doesn't load."? Any assets associated with your Laravel project should reference the/get-started/subdir, assuming that is where they are located... As in your example,example.com/get-started/build/assets/main.3843b6a5.jswould get rewritten toexample.com/get-started/public/build/assets/main.3843b6a5.js- which I assume is the intention?