Ibrahim Azhar Armar
Ibrahim Azhar Armar

Reputation: 25753

ErrorDocument 404 to External URL

We have moved our website to new domain name, for SEO purpose we are required to redirect all 404 to new domain name.

Our website domain : example.com
Moved to: new-domain.com/example

Any non-existent url for domain such as example.com/non-existent to new-domain.com/example/non-existent

I tried with following in my .htaccess file and It does not work.

ErrorDocument 404 http://new-domain.com/example/%{REQUEST_URI}

This is a WordPress installation, apart from handing this with WordPress hook, is there a htaccess solution?

I am on Ubuntu 16.04 with Apache version 2.4.18

Thanks.

Upvotes: 0

Views: 794

Answers (1)

Panama Jack
Panama Jack

Reputation: 24478

You can't mix error document with server variables like that. You can try using a mod-rewrite. Put this rule above your current wordpress rules.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?old-example\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ http://www.new-example.com/example%{REQUEST_URI} [R=301,L]

Upvotes: 2

Related Questions