How best to redirect a webpage without using Javascript?

独自空忆成欢 提交于 2019-12-13 03:17:59

问题


I have some script in my default page that redirects users to language specific versions of my website depending on the language of the browser. I want to add something that redirects those users who do NOT have Javascript enabled.

Currently I have the following :

<noscript>
  <META HTTP-EQUIV=REFRESH CONTENT="1; URL=en/index.htm">.
</noscript>

But I've read this is not too wise as some search engines frown upon it. How do I do this and keep search engines happy?


回答1:


You can redirect at server side with 301 HTTP status code too. This is the best way to do it for good SEO. The example is in C# but every plattform has his own method to add headers to the response:

Response.Clear();
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location", "/newfolder/newfilelocation");

The reason to use the 301 status code is that the search engine indexes the new page because it was "Moved permanently" instead of the 302 that was "Moved temporarily".




回答2:


You should use a .htaccess file to detect the browser's language from the headers (using a regular expression) and then redirect them that way. Doing that is completely agnostic of the client-side configuration and search engines will handle it properly. There is a ton of information out there on specifically how to accomplish this.




回答3:


It could be done with a server side language by adding the following http header

Location: /en/index

will redirect the user to http://www.example.com/en/index




回答4:


You'll need to parse the Accept-Language HTTP header.




回答5:


Why don't you redirect on the server side, by responding with a 302 HTTP status code. I don't know what you have on the server, but all frameworks support it.



来源:https://stackoverflow.com/questions/875318/how-best-to-redirect-a-webpage-without-using-javascript

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