输入URL以跳转到另一个页面,更改操作方式

时间:2012-02-11 12:48:44

标签: php

考试

输入http://111.111.111.111/aaa.co.uk/web/

默认跳转到

http://111.111.111.111/aaa.co.uk/web/upload.html

你是怎么做到的?

我尝试这样做

修改.htacess

Redirect /aaa.co.uk/web/ /aaa.co.uk/web/upload.html

但是网址显示

http://111.111.111.111/aaa.co.uk/web/upload.html/upload.html/upload.html/upload.html/upload.html/upload.html/upload.html/upload.html/upload.html/upload.html/upload.html
......

3 个答案:

答案 0 :(得分:2)

是否需要.htaccess?

所以对于页面:

http://111.111.111.111/aaa.co.uk/web/

该页面的index.php文件可以包含:

header("HTTP/1.1 301 Moved Permanently"); 
header("Location: http://111.111.111.111/aaa.co.uk/web/upload.html");
exit;

修改

如果需要.htaccess,可能就像下面的那样?

RewriteRule ^/aaa\.co\.uk/web/$ /aaa\.co\.uk/web/upload\.html [R=301,L]

请注意分隔符和301永久重定向规则。

答案 1 :(得分:2)

试试这个.htaccess

Redirect /aaa.co.uk/web/$ /aaa.co.uk/web/upload.html

$告诉apache只重定向/aaa.co.uk/web,而不是从该字符串开始。

答案 2 :(得分:0)

您可以使用Header()功能,它就是这样:

Header("Location: yourredirecturl.php");
die();

你也可以添加

Header( "HTTP/1.1 301 Moved Permanently" ); 

die();之前它将返回301的标题,请检查它是否应该重定向为永久或临时(SEO问题)。