将所有请求重定向到index.html

问题描述:

我试图将所有未知请求重定向到index.html。例如,如果有人输入:将所有请求重定向到index.html

http://IP_Address/blah_blah _blah 

然后它必须重定向到index.html。下面是我曾尝试代码:

/var/www/some_dir/index.html

RewriteEngine on 
RewriteCond %{REQUEST_URI} !^/index.html$ 
RewriteRule . index.html [R=302,L] 

当我尝试这种代码在我的根目录,它重定向到http://Ip_address/var/www/accesspage/index.html

我想http://Ip_address/index.html

但我想通过index.html重定向到其他html页面

下面是我的Apache配置

DocumentRoot /var/www/access/ 
<Directory /> 
    Options FollowSymLinks 
    AllowOverride None 
</Directory> 
<Directory /var/www/access/> 
    Options Indexes FollowSymLinks MultiViews 
    AllowOverride All 
    Order allow,deny 
    allow from all 
</Directory> 
+0

如果我没有弄错,你的web服务器配置会变得很棘手。 – user982270 2013-03-01 05:59:01

+0

我已经添加了apache congi来检查它,它的所有版本 – EnterJQ 2013-03-01 06:03:10

+1

试试这个:'RewriteRule。 /index.html [R = 302,L]' – 2013-03-01 06:43:36

只需使用.htaccess制作自定义404页面,并在该页面上使用header()来重定向用户。 (如果你不想使用PHP,你也可以使用javascript重定向)

+0

对不起,我没有得到你:( – EnterJQ 2013-03-01 06:02:06

+0

做一个页面名称404.html,并在你的htaccess文件中写入: ErrorDocument 404 /404.html。然后 在404.html页面重定向用户使用javascript – WhiteBlue 2013-03-01 06:10:16

+0

谢谢哥们:) – EnterJQ 2013-03-01 07:15:15