如何在wordpress中使用htaccess将404页面重定向到新的(子)域?

问题描述:





对于客户我想用.htaccess做以下事情:



domainname.com/path必须重定向到sub.domainname.com/path,但前提是第一页是已删除的页面/ 404页面。



所以所有现有页面必须保持不变,并且已删除的页面必须重定向到具有相同路径的子域。



我在Wordpress网站上使用以下代码,仅重定向404错误页面到新域:



Hi,

For a client I want to do the following thing with .htaccess:

domainname.com/path must redirect to sub.domainname.com/path, but only if the first page is a deleted page / 404 page.

So all the existing pages must stay intact, and the deleted pages must redirect to a subdomain with the same path.

I used the following code on a Wordpress website, to only redirect 404 error pages to a new domain:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^ http://example.com%{REQUEST_URI} [L,R=301]





我在现有的htaccess文件中覆盖了以下代码:





I have overwritten the following code in the existing htaccess file:

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





它不起作用。问题是现在所有页面都被重定向到新域。



只有404必须重定向。



我有什么不对?



谢谢!



我尝试过:



尝试了不同的htaccess代码



It is not working. The problem is that now ALL pages are redirected to the new domain.

Only the 404's must be redirected.

What do I wrong?

Thanks!

What I have tried:

Tried different htaccess codes

[NC]
RewriteCond% {REQUEST_FILENAME}!-f
RewriteCond%{REQUEST_FILENAME}!-d
RewriteRule ^ http://example.com% {REQUEST_URI} [L,R = 301]
[NC] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^ http://example.com%{REQUEST_URI} [L,R=301]





我在现有的htaccess文件中覆盖了以下代码:





I have overwritten the following code in the existing htaccess file:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php


- [L]
RewriteCond%{REQUEST_FILENAME}!-f
RewriteCond%{REQUEST_FILENAME}!-d
RewriteRule。 /index.php [L]
< / IfModule>
- [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule>





它不起作用。问题是现在所有页面都被重定向到新域。



只有404必须重定向。



我有什么不对?



谢谢!



我尝试过:



尝试了不同的htaccess代码



It is not working. The problem is that now ALL pages are redirected to the new domain.

Only the 404's must be redirected.

What do I wrong?

Thanks!

What I have tried:

Tried different htaccess codes