301 Redirect with custom message

浪尽此生 提交于 2019-12-13 08:52:34

问题


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?


回答1:


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:

  1. 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 use setTimeout() functionality.

  2. 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">



来源:https://stackoverflow.com/questions/7042234/301-redirect-with-custom-message

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!