vinni vinni - 7 months ago 32
PHP Question

htacess different 404 on wordpress subfolder

I have a

Wordpress
installation at the sub-folder
www.domain.com/blog
of my domain. It has it's own 404 page which unfortunately also shows if a page can't be found on my main website.

I'd like to have a
404
redirection of my main Website and the Wordpress one for my blog in the subfolder.

This is the code I have until now. But the second one is overwriting the first. How can I make the wordpress redirection only apply to the subfolder?

RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www\.)?domain\.com$ [NC]
RewriteRule ^(.*) http://www.domain.com/$1 [R=301,NE,L]

ErrorDocument 404 /notfound/404.html

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

Answer

Ok, if your main website is www.domain.com and your WP blog is www.domain.com/blog then why both WP and non-WP rules are in the same .htaccess file? I mean, your WP in a subfolder should have its .htaccess in that same subfolder, while the main website has a different .htaccess in root folder.

EDIT: assuming that the main website is not WP, you should have 2 different .htaccess files. The first one with non-WP rules goes to main website directory and looks like this:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www\.)?domain\.com$ [NC]
RewriteRule ^(.*) http://www.domain.com/$1 [R=301,NE,L]
ErrorDocument 404 /notfound/404.html

The second is just a regular WP .htaccess file and goes to WP directory:

RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]

That will do the trick.

Comments