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