I’ve installed a WordPress blog in the public directory of my Laravel project by creating a new folder named blog and placing the WordPress files inside it. When I search localhost:8000/blog, it redirects to localhost:8000/public/blog/, but when I add a trailing slash and search localhost:8000/blog/, it opens the WordPress blog as expected.
How can I resolve this issue so that localhost:8000/blog correctly opens the WordPress blog without needing the trailing slash?
The condition RewriteCond %{REQUEST_FILENAME} !-f" covers the case of the "blog" folder inside public. Once there, the problem is with the configuration of the .htaccess folder or the configuration of the wordpress
@edumetal If I move the blog folder out of the Laravel's public , will it still be accessible as expected? Are there any potential issues or additional steps I should be aware of to ensure everything continues to work smoothly?
@Digipl If you can move the folder out of 'public' then you have access to the web server settings. This gives you more configuration possibilities like creating a subdomain for your blog (recommended). The settings you apply to the .htaccess inside the 'blog' folder will still work. If you want to just change the physical location of the 'blog' and keep it in your site root then you can opt for an alias.
try to put the laravel bypass rule first, the order matters in the htaccess file, you must ensure that any request for public/blog will redirect to blog before redirecting to the laravel index
RewriteEngine On
# Bypass Laravel for the /blog directory
RewriteCond %{REQUEST_URI} ^/blog(/|$) [NC]
RewriteRule ^blog(/|$) - [L]
# Prevent redirect loop for /blog without a trailing slash
RewriteCond %{REQUEST_URI} ^/blog$ [NC]
RewriteRule ^blog$ /blog/ [L,R=301]
# 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 (Laravel)...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]