301使用自定义消息重定向 [英] 301 Redirect with custom message
问题描述
是否仍然可以使用.htaccess对自定义消息进行301重定向?
例如.在重定向开始之前,它将说:我们已经永久移至abc.com,并且该域将很快过期.因此,请相应地更新您的书签.您将在10秒内被重定向."
还是只有PHP或其他编程语言才可以?
否-因为301代码必须在服务器端发布.浏览器/搜索机器人会检查响应代码,如果代码为301,它将忽略与它一起发送的任何内容.
您可以显示这样的页面并重定向到新的URL ..但这与常规点击链接相同,因此不适用于SEO.如果有兴趣-这是可以完成的方法:
当用户点击此类页面时,向他/她显示您的重定向消息/页面.在该页面中,可以通过两种方式实现这种重定向:
-
使用JavaScript-
window.location = "http://www.example.com/new-url"
.您所需要做的就是在页面加载后10秒钟执行此代码-为此使用setTimeout()
功能. -
使用
<meta http-equiv="refresh"
标头行不使用JavaScript(首选方法,即使禁用了JavaScript也不可用,它仍可使用):<meta http-equiv="refresh" content="10; url=http://www.example.com/new-url">
Is there anyway to do 301 Redirect with custom message using .htaccess?
Eg. Before the redirect begins, it will say: "We have moved permanently to abc.com and this domain will be expired soon. So please update your bookmark accordingly. You will be redirected in 10 seconds."
Or that's only possible with PHP or other programming languages?
No -- because 301 code has to be issued on the server side. Browser/Search bot checks the response code and if code is 301 it will ignore any content that was sent together with it.
You can display such page and do redirect to a new URL .. but this will be the same as normal click on a link and therefore is not good for SEO purposes. If interested -- this is how it can be done:
When user hits such page, show him/her your redirect message/page. In that page such redirect can be achieved in 2 ways:
Using JavaScript --
window.location = "http://www.example.com/new-url"
. All what you need to do is to execute this code 10 seconds after page is loaded -- for that usesetTimeout()
functionality.Without JavaScript (preferred method as it will work even if JavaScript is disabled or not available) using
<meta http-equiv="refresh"
header line:<meta http-equiv="refresh" content="10; url=http://www.example.com/new-url">
这篇关于301使用自定义消息重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!