Click here to Skip to main content
15,887,585 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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]


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>


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
Posted
Updated 23-May-17 0:12am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900