重定向我的服务器中不存在的任何 URL


Redirect any URL that doesn't exists in my server

我已经在客户以前的域中进行了DNS更改,所以现在所有类似 ABCDEF.com 的URL现在都翻译成 UVWXYZ.com,但是我的客户希望维护指向其页面的每个链接,并且我正在通过htaccess和mod_rewrite进行一组很好的301重定向。所以现在我的.htaccess看起来像这样:

RewriteEngine On
RewriteBase /
RewriteRule ^list.aspx?i=5$ list.php [R=301,L]
RewriteRule ^cat.aspx?i=1$ printers.php [R=301,L]
RewriteRule ^cat.aspx?i=3$ multi.php [R=301,L]

此时,当我输入 ABCDEF.com/list.aspx 时,我的浏览器加载 UVWXYZ.com/list.php(其他示例也是如此),但我的客户端想要将任何其他页面重定向到主页。换句话说,当我输入 ABCDEF.com/downloads.aspx 时,我的浏览器必须加载 UVWXYZ.com。

我尝试过这样的规则

RewriteRule (.*) index.php [R=301,L]

但是服务器喊出重定向循环。哪条规则最适合我的情况?

提前非常感谢

您可以尝试以下方法之一:

FallbackResource /index.php

或:

ErrorDocument 404 /index.php

或者只用mod_rewrite(在你的htaccess文件的最后):

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^ /index.php [L,R=301]