Redirect 404 errors to another URL
Posted: September 7, 2012 Filed under: NEZzen Leave a comment »Here’s a few lines I added to the .htaccess file on an Apache web server to redirect all “not-found” requests to another domain name. Useful if you want to have one domain point to another, but still be able to retain access to files only available on the first one.
RewriteEngine On
RewriteBase /
# index.html must be forwarded since access to / will redirect to /index.html (default page)
RewriteRule ^index.html$ http://example.com/ [L]
# if the file or directory with the requested name doesn't exist...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
# forward the request by rewriting the domain name
RewriteRule ^(.*)$ http://example.com/$1 [L]