问题
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:
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">
来源:https://stackoverflow.com/questions/7042234/301-redirect-with-custom-message