Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Digipl's avatar
Level 1

WordPress in Laravel

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?

0 likes
9 replies
jlrdw's avatar

Are you setup correctly pointing to public as the document root?

Digipl's avatar
Level 1

@jlrdw .htaccess file <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}]

# Prevent redirect loop for /blog without a trailing slash
RewriteCond %{REQUEST_URI} ^/blog$ [NC]
RewriteRule ^blog$ /blog/ [L,R=301]

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

# Bypass Laravel for the /blog directory
RewriteCond %{REQUEST_URI} ^/blog(/|$) [NC]
RewriteRule ^blog(/|$) - [L]

# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
Snapey's avatar

You should avoid applying any rewrite to /blog

1 like
edumetal's avatar

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

Digipl's avatar
Level 1

@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?

edumetal's avatar

@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.

puklipo's avatar

It's better not to do this. Run Laravel and WordPress separately.

gfucci's avatar

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]

Please or to participate in this conversation.