htaccess wordpress子文件夹上的不同404


htaccess different 404 on wordpress subfolder

我在域的子文件夹www.example.com/blog中安装了Wordpress。它有自己的404页面,不幸的是,如果在我的主网站上找不到页面,它也会显示。

我想对我的主网站进行404重定向,并在子文件夹中为我的博客进行Wordpress重定向。

这是我到现在为止的代码。但第二个是重写第一个。如何使wordpress重定向仅应用于子文件夹?

RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www'.)?example'.com$ [NC]
RewriteRule ^(.*) http://www.example.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>

好的,如果你的主网站是www.domain.com,而你的WP博客是www.domain.com/blog,那么为什么WP和非WP规则都在同一个.htaccess文件中?我的意思是,你的WP在一个子文件夹中应该有它的.htaccess在同一个子文件夹,而主网站在根文件夹中有一个不同的.htacccess。

编辑:假设主网站不是WP,你应该有两个不同的.htaccess文件。第一个有非WP规则的转到主网站目录,看起来像这样:

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

第二个文件只是一个常规的WP.htaccess文件,并转到WP目录:

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

那就行了。