将404重定向到另一个具有相同文件路径的网站


0

有没有一种创建链接的方法,该链接将以某种方式执行此操作:如果用户转到 http://website1.com/path/to/file,并且结果为“ 404”,则该链接不存在,请使其自动导航到http://website2.com/path/to/file。我希望/ path / to / file保留下来,但只更改域。

在ubuntu 10.10服务器上运行的apache2中,有没有办法做到这一点?


1
mod_rewrite在适当条件下可能会起作用。
丹尼尔·贝克

Answers:


1

您可以使用mod重写来执行此操作,如下所示:

确保您已启用Mod重写

a2enmod rewrite

编辑您的vhost或httpd.conf或.htaccess的配置文件-使用哪种方式来设置apache服务器。

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

您可能需要进行一些微调-您没有提供很多设置细节。但是上面的概念会起作用。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.