0

我一直在环顾四周,但找不到确切的解决方案。

我有一个要重定向的网站,除非他们输入任何现有的 URL。

例如(这些应该在有或没有 www 的情况下工作):

www.site.com -> redirect to sub.site.com
www.site.com/nonexistant.php -> does not so redirect to sub.site.com
www.site.com/index1.php -> exists so show it

任何帮助表示赞赏!谢谢,克里斯

4

2 回答 2

1

如果我了解您要正确执行的操作,则应该这样做;

# Turn rewrites on
RewriteEngine On

# First rewrite the site root to the new site.    
RewriteRule ^$ http://sub.site.com [L,R=301]

# ...else if the request doesn't match a directory...
RewriteCond %{REQUEST_FILENAME} !-d

# ...and it doesn't match a file...
RewriteCond %{REQUEST_FILENAME} !-f

# ...then redirect to http://sub.site.com/
RewriteRule ^.*$ http://sub.site.com [L,R=301]
于 2012-09-20T20:05:49.723 回答
0

创建一个用户定义的 404 页面并将其放入其中:

<?php

header("Location: http://sub.site.com");

?>
于 2012-09-20T19:40:11.470 回答