Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Is there a way to create a link that will in a way do this: If the user goes to http://website1.com/path/to/file and if it results in "404" it doesnt exist, make it automatically navigate to http://website2.com/path/to/file. I want the /path/to/file to carry over but just the domain change.

Is there a way to do this in apache2 running on ubuntu 10.10 server?

share|improve this question
1  
mod_rewrite with appropriate condition might work. –  Daniel Beck May 1 '13 at 14:41
add comment

1 Answer

up vote 1 down vote accepted

You can do this with mod rewrite as follow:

Make sure you have mod rewrite enabled

a2enmod rewrite

Edit your configuration file for your vhost or httpd.conf or .htaccess - which ever way you are setting up your apache server.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ http://website2.com/$1

You may need to tweak this slightly - you did not provide a lot of details on your setup. But the concept above will work.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.