Search code examples
wordpress.htaccessmagento2subdirectoryfishpig

Setup WordPress as a sub folder in Magento 2 directory


I have Magento 2 and want to setup WordPress in a subfolder, so it will be accessed via magento2.url/blog

I know about Fishpig but for my situation, it will not work because WordPress site has a lot of custom post types which is not supported by FishPig integration by default.

Right now if I tried to access magento2.url/blog it shows a 404 error Magento 2 page.

I modified .htaccess in WordPress subfolder to this:

# BEGIN WordPress
<IfModule mod_rewrite.c>

RewriteEngine On

RewriteBase /blog/

RewriteRule ^index\.php$ - [L]

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . /blog/index.php [L]

</IfModule>

# END WordPress 

But it not helps and home page for WordPress still shows a 404 Magento 2 page. I think I need to modify .htaccess in Magento 2 but not really sure how.


Solution

  • The .htaccess is irrelevant when integrating WordPress into Magento. This file only applies when accessing WordPress directly (ie. for a WordPress Admin request).

    Here are basic installation instructions:

    • Install WordPress in a sub-directory of Magento called wp.
    • If you use the pub directory to display Magento, either install WordPress at pub/wp or create a symlink at pub/wp to point to the actual wp folder.
    • Check the wp_options table for the home and siteurl values. The siteurl value should be the /wp URL and the home option should be your /blog URL

    This is all you need to do to integrate WordPress at /blog.

    The .htaccess file has no impact here, however you should change /blog/ to /wp/ in the .htaccess for WordPress. The correct value is:

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /wp/
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /wp/index.php [L]
    </IfModule>
    
    # END WordPress
    

    For a full installation guide, see this link.