How best to redirect a webpage without using Javas

2019-08-20 06:38发布

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?

5条回答
趁早两清
2楼-- · 2019-08-20 07:18

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

查看更多
Fickle 薄情
3楼-- · 2019-08-20 07:22

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

查看更多
三岁会撩人
4楼-- · 2019-08-20 07:22

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.

查看更多
闹够了就滚
6楼-- · 2019-08-20 07:37

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.

查看更多
登录 后发表回答