1

I used Installatron to install Wordpress in a subdirectory of an existing PHP website, to add a blog to that website. My main website is administered via cPanel.

Here's my website directory structure:

/-- public_html
    /-- .htaccess
    /-- index.php
    /-- about.php
    /-- etc.
    /-- product-pages
        /-- index.php
        /-- product-a.php
        /-- product-b.php
        /-- etc.
    /-- blog
        /-- wp-admin
        /-- wp-content
        /-- wp-includes
        /-- .htaccess
        /-- .user.ini
        /-- index.php
        /-- etc.

The Wordpress installation added the standard Wordpress section to the root .htaccess:

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

# END WordPress

As many people have found, this disables my custom 404 error pages for the main website, displaying the site homepage instead. 404 errors for the Wordpress blog work as expected and display the Wordpress custom 404 error.

Wordpress also created a .htaccess in its own /blog installation directory. It includes this section:

# 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

I found that by removing the Wordpress section from the .htaccess in the main website root, both main website custom 404 and Wordpress custom 404 functionality appear to work correctly. Is there any reason why I shouldn't do this?

Is the addition of a Wordpress section to the root .htaccess by the Installatron Wordpress installer incorrect behaviour for a subdirectory installation?

1
  • It would seem like unwanted behaviour to me? Others may have a different view but as far as I know, those Wordpress specific rules only need to be in the root of the WP install, so in your case its only needed in the subfolder. I think you can open a ticket with Installatron - it might be worth passing on your observations in case its something they'd identify as a bug?
    – t2pe
    Commented Aug 20, 2020 at 11:34

1 Answer 1

1

I found that by removing the Wordpress section from the .htaccess in the main website root, both main website custom 404 and Wordpress custom 404 functionality appear to work correctly. Is there any reason why I shouldn't do this?

Yes, this is what I was going to suggest.

If WordPress is installed in the subdirectory /blog and is accessed by the URL /blog/ then there is no need for the WordPress .htaccess file in the document root. You certainly shouldn't have both.

However, the "WordPress" .htaccess file in the document root would seem to be rewriting to /index.php in the document root, which is incorrect anyway?!

Is the addition of a WordPress section to the root .htaccess by the Installatron Wordpress installer incorrect behaviour for a subdirectory installation?

Well, you would need an .htaccess file in the root if you installed WordPress in the /blog subdirectory, but the /blog subdirectory was hidden from the URL-path. (It would, however, be written differently to the current .htaccess file in root. In fact, it would be the same as the .htaccess file currently in the /blog subdirectory.)

5
  • Thanks for this. I did try modifying the Wordpress section in the root .htaccess file to match the one in the /blog subdirectory .htaccess file. However, this resulted in all pages and subdirectories in the main website, other than the root index.php, generating the /blog Wordpress 404 error.
    – Ukebloke
    Commented Aug 21, 2020 at 14:08
  • You would also need to modify the WordPress config to remove /blog from the generated URLs. However, to do what you were trying to do initially, you should remove the .htaccess file in the root altogether.
    – MrWhite
    Commented Aug 21, 2020 at 14:44
  • I can't remove the .htaccess file in the root, as it contains configuration details for the main website. I just removed the Wordpress section, which had been added automatically by the Wordpress install process.
    – Ukebloke
    Commented Aug 24, 2020 at 7:40
  • "I just removed the Wordpress section" - Yes, just remove the relevant WordPress directives. (WordPress will only manage one .htaccess file, so it's quite possibly just a leftover from the install process?)
    – MrWhite
    Commented Aug 24, 2020 at 12:31
  • 1
    Thanks for your help @MrWhite. The only reason I hadn't marked the question as accepted is because I was hoping someone might be able to advise me on whether or not the creation of a Wordpress section in the root .htaccess is a known installation issue. As you suggested, it may be a leftover from the install process, but as this was a vanilla subdirectory installation, I wouldn't expect it to touch any files or directories outside the Wordpress install destination.
    – Ukebloke
    Commented Aug 25, 2020 at 13:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.