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?
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?
- 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
Reset to default 1I 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.)