- 浏览: 95131 次
- 性别:
- 来自: 上海
最新评论
-
shmily2038:
有相应的例子? 给的全部是英文,还不如自己看官网e文。 上代 ...
ActiveMQ集群随记 -
lutian1984:
你好,你验证过你转发的这个东西吗?为什么在我这里还是报错呢?
jquery.form.js ajax上传文件问题 -
chenhongwei0924:
精辟.
如何防止SQL注入 -
fairyhawk:
简单的几句,经验的总结。
如何防止SQL注入 -
joliny:
谢谢了,这个问题也困扰了我很久、!
Apache整合Tomcat后get方式提交中文乱码问题解决
本文引自:http://www.stevenhargrove.com/redirect-web-pages/
The internet today is full of webmasters that are always updating, editing and even deleting web pages.
Lets say you are updating your website completely, changing the names of page's filenames (ex: file.html to file.php) and so on, this is great, you should stay updated! But what if you want to get rid of those old pages without having to worry about those who go to the old web page and see nothing? It doesnt end there either, other visitors do include major search engines such as MSN, Google and Yahoo! If people are finding your old pages when querying in these search engines, and they attempt to go to that page that has been deleted or moved, they will get a "404 File Not Found" Error! Now i know you dont want that, no webmaster wants that!
UPDATE: For those of you still confused on what web page redirection is, I have written a follow-up article titled Understanding Web Page Redirection, the smart way, to help answer some of the questions I most commonly get in the comments of this article.
The 301 Redirect
The best way to redirect those pages is by using something called a "301 Redirect". What this 301 redirect does, is it blatantly redirects to a different page when it is triggered. What makes the 301 redirect the best? Not only does it accomplish your redirect - it does it safely. No having to worry about the search engines penalizing you for it. To be specific, the 301 redirect tells the browser, or in other cases, it tells the search engines "Hey this page has been moved, here is the correct URL!". Think of it as you getting mail that is not addressed to your name. Possibly addressed to somebody who has lived there prior to yourself. What do you do? You tell the post man (or woman) "Hey they don't live here anymore, here is the correct address". It is the same concept, pretty simple stuff.
So lets get started. Below you will see several methods of using the 301 redirect, including the redirect in PHP, the redirect in ASP, the redirect in ASP .NET, the redirect in JSP (JAVA), the redirect in IIS, the redirect in ColdFusion, the redirect in CGI/PERL and finally the one I find most useful, the redirect using htaccess. Also showing other useful ways of using the 301 redirect with mod_rewrite!
HTML Redirection
How do you redirect using html you ask? Here is how: DONT!
Over the past 8-10 years, use of meta tag refresh redirection has been abused for uses in relation to SPAM. The result of this and other scenarios of mis-uses of it, is that when using it, that page WILL be de-indexed from every search engine.
NOTE: This also applies to javascript redirection. Search engines can easily detect javascript and meta tag redirection, so just dont do it, use the 301 redirect.
Now, this doesn't necessarily apply to *everything*. If it is used properly, then you have nothing to worry about. For example, often on many forum engines - you will see when you perform different tasks such as making a thread, replying to one or even things like logging in - you will notice it takes you to a "please wait a moment" screen. On those types of pages, they are using either javascript or meta tag redirection, and its perfectly legit.
Canonical Links
My first impression of canonical links is "Great, but where the hell were you 10 years ago?". That aside, from what I see they really are for one purpose: dynamic content.
To put that into perspective, I have a wordpress plugin on this blog that will separate my comments onto multiple pages, so I don't have to show 500+ comments on one single page. So it paginates the comments for me.
The slight drawback to this, is that since it is paginating my comments onto several pages - this exact article data exists on those pages as well. So those page url's end up looking like this: http://www.stevenhargrove.com/redirect-web-pages/comment-page-50/. When really, it is just the same page with different comments.
Using canonical links, I could specify in the of the html document my canonical link. Which would look like this:
HTML:
Another interesting bit to consider about canonical links:
Can this link tag be used to suggest a canonical URL on a completely different domain?
No. To migrate to a completely different domain, permanent (301) redirects are more appropriate. Google currently will take canonicalization suggestions into account across subdomains (or within a domain), but not across domains. So site owners can suggest www.example.com vs. example.com vs. help.example.com, but not example.com vs. example-widgets.com.
Matt Cutts has a great article that shows how to use these more in depth. He also has a slide show that covers it a bit.
301 Redirect Using htaccess
Using htaccess to accomplish the 301 redirect is highly suggested due to it being fairly convenient to manage, rather than setting redirects on each individual page, you can simply add the redirect code to the .htaccess file.
Here is how to do it:
1. Create a file on the root directory of your website, name it ".htaccess".
2. Open the .htaccess file using notepad or what ever text editor that you prefer.
3. Add this into the .htaccess file, save it and then upload it to your web server:
NOTE: Don't add "http://www" to the first part of the statement - place the path from the top level of your site to the page. Also ensure that you leave a single space between these elements:
redirect 301 (the instruction that the page has moved)
/old/old.html (the original folder path and file name)
http://www.you.com/new.html (new path and file name)
Also note that you are not required to redirect the page to another domain, an equally useful purpose for using the 301 redirect, is redirecting old pages to the new pages on the same domain, it all works the same way!
UPDATE: .htaccess Editor is a simple, yet useful resource for generating htaccess files.
301 Redirect Using Mod_Rewrite
Mod_Rewrite has got to be one of the most usefull modules a server can have in terms of SEO, it allows to organize the file structure of your web site in a dynamic yet simple fashion, in this example I show a useful method of 301 redirecting with mod_rewrite.
When somebody links to your website, sometimes they dont always link to you in the way that you want them to. If somebody links to www.yoursite.com and somebody else links to yoursite.com, Google will assign a separate pagerank for each of those. Yes, it is stupid but it is true, by inserting the below example into your .htaccess file, it will solve the problem by redirecting anything linking to yoursite.com to www.yoursite.com, also redirecting the pagerank, so no worries!
301 Redirect Using IIS
1. In internet services manager, right click on the file or folder you wish to redirect.
2. Select the radio titled "a redirection to a URL".
3. Enter the page that the page will be redirected to.
4. Check "The exact url entered above" and the "A permanent redirection for this resource".
5. Click on 'Apply'.
301 Redirect Using ColdFusion
As well as many server side scripting languages, using the 301 redirect in them is fairly simple.
Simply add this code to your ColdFusion page:
301 Redirect Using PHP
Simply add this code to your page or script:
301 Redirect Using ASP
Simply add this code to your page or script:
301 Redirect Using ASP .NET
Simply add this code to your page or script:
301 Redirect Using JSP/JAVA
Simply add this code to your page or script:
301 Redirect Using CGI/PERL
Simply add this code to your cgi/perl script:
301 Redirect Using Ruby/Ruby on Rails
Simply add this code to your ruby/ruby on rails script:
Zachary Pinter has a nice explanation of this.
Pleaee note that all of the snippets of code above are examples and I have tested each at some point. However, I am in no way responsible for any damage the code may cause, you use this code at your own risk.
The internet today is full of webmasters that are always updating, editing and even deleting web pages.
Lets say you are updating your website completely, changing the names of page's filenames (ex: file.html to file.php) and so on, this is great, you should stay updated! But what if you want to get rid of those old pages without having to worry about those who go to the old web page and see nothing? It doesnt end there either, other visitors do include major search engines such as MSN, Google and Yahoo! If people are finding your old pages when querying in these search engines, and they attempt to go to that page that has been deleted or moved, they will get a "404 File Not Found" Error! Now i know you dont want that, no webmaster wants that!
UPDATE: For those of you still confused on what web page redirection is, I have written a follow-up article titled Understanding Web Page Redirection, the smart way, to help answer some of the questions I most commonly get in the comments of this article.
The 301 Redirect
The best way to redirect those pages is by using something called a "301 Redirect". What this 301 redirect does, is it blatantly redirects to a different page when it is triggered. What makes the 301 redirect the best? Not only does it accomplish your redirect - it does it safely. No having to worry about the search engines penalizing you for it. To be specific, the 301 redirect tells the browser, or in other cases, it tells the search engines "Hey this page has been moved, here is the correct URL!". Think of it as you getting mail that is not addressed to your name. Possibly addressed to somebody who has lived there prior to yourself. What do you do? You tell the post man (or woman) "Hey they don't live here anymore, here is the correct address". It is the same concept, pretty simple stuff.
So lets get started. Below you will see several methods of using the 301 redirect, including the redirect in PHP, the redirect in ASP, the redirect in ASP .NET, the redirect in JSP (JAVA), the redirect in IIS, the redirect in ColdFusion, the redirect in CGI/PERL and finally the one I find most useful, the redirect using htaccess. Also showing other useful ways of using the 301 redirect with mod_rewrite!
HTML Redirection
How do you redirect using html you ask? Here is how: DONT!
Over the past 8-10 years, use of meta tag refresh redirection has been abused for uses in relation to SPAM. The result of this and other scenarios of mis-uses of it, is that when using it, that page WILL be de-indexed from every search engine.
NOTE: This also applies to javascript redirection. Search engines can easily detect javascript and meta tag redirection, so just dont do it, use the 301 redirect.
Now, this doesn't necessarily apply to *everything*. If it is used properly, then you have nothing to worry about. For example, often on many forum engines - you will see when you perform different tasks such as making a thread, replying to one or even things like logging in - you will notice it takes you to a "please wait a moment" screen. On those types of pages, they are using either javascript or meta tag redirection, and its perfectly legit.
Canonical Links
My first impression of canonical links is "Great, but where the hell were you 10 years ago?". That aside, from what I see they really are for one purpose: dynamic content.
To put that into perspective, I have a wordpress plugin on this blog that will separate my comments onto multiple pages, so I don't have to show 500+ comments on one single page. So it paginates the comments for me.
The slight drawback to this, is that since it is paginating my comments onto several pages - this exact article data exists on those pages as well. So those page url's end up looking like this: http://www.stevenhargrove.com/redirect-web-pages/comment-page-50/. When really, it is just the same page with different comments.
Using canonical links, I could specify in the of the html document my canonical link. Which would look like this:
HTML:
<link rel="canonical" href="http://www.stevenhargrove.com/redirect-web-pages/" />
Another interesting bit to consider about canonical links:
Can this link tag be used to suggest a canonical URL on a completely different domain?
No. To migrate to a completely different domain, permanent (301) redirects are more appropriate. Google currently will take canonicalization suggestions into account across subdomains (or within a domain), but not across domains. So site owners can suggest www.example.com vs. example.com vs. help.example.com, but not example.com vs. example-widgets.com.
Matt Cutts has a great article that shows how to use these more in depth. He also has a slide show that covers it a bit.
301 Redirect Using htaccess
Using htaccess to accomplish the 301 redirect is highly suggested due to it being fairly convenient to manage, rather than setting redirects on each individual page, you can simply add the redirect code to the .htaccess file.
Here is how to do it:
1. Create a file on the root directory of your website, name it ".htaccess".
2. Open the .htaccess file using notepad or what ever text editor that you prefer.
3. Add this into the .htaccess file, save it and then upload it to your web server:
Redirect 301 /old/old.html http://www.you.com/new.html
NOTE: Don't add "http://www" to the first part of the statement - place the path from the top level of your site to the page. Also ensure that you leave a single space between these elements:
redirect 301 (the instruction that the page has moved)
/old/old.html (the original folder path and file name)
http://www.you.com/new.html (new path and file name)
Also note that you are not required to redirect the page to another domain, an equally useful purpose for using the 301 redirect, is redirecting old pages to the new pages on the same domain, it all works the same way!
UPDATE: .htaccess Editor is a simple, yet useful resource for generating htaccess files.
301 Redirect Using Mod_Rewrite
Mod_Rewrite has got to be one of the most usefull modules a server can have in terms of SEO, it allows to organize the file structure of your web site in a dynamic yet simple fashion, in this example I show a useful method of 301 redirecting with mod_rewrite.
When somebody links to your website, sometimes they dont always link to you in the way that you want them to. If somebody links to www.yoursite.com and somebody else links to yoursite.com, Google will assign a separate pagerank for each of those. Yes, it is stupid but it is true, by inserting the below example into your .htaccess file, it will solve the problem by redirecting anything linking to yoursite.com to www.yoursite.com, also redirecting the pagerank, so no worries!
RewriteEngine On rewritecond %{http_host} ^yoursite.com rewriteRule ^(.*) http://www.yoursite.com/$1 [R=301,L]
301 Redirect Using IIS
1. In internet services manager, right click on the file or folder you wish to redirect.
2. Select the radio titled "a redirection to a URL".
3. Enter the page that the page will be redirected to.
4. Check "The exact url entered above" and the "A permanent redirection for this resource".
5. Click on 'Apply'.
301 Redirect Using ColdFusion
As well as many server side scripting languages, using the 301 redirect in them is fairly simple.
Simply add this code to your ColdFusion page:
<cfheader statuscode="301" statustext="Moved permanently"> <cfheader name="Location" value="http://www.new-url.com/">
301 Redirect Using PHP
Simply add this code to your page or script:
<? header( "HTTP/1.1 301 Moved Permanently" ); header( "Status: 301 Moved Permanently" ); header( "Location: http://www.new-url.com/" ); exit(0); // This is Optional but suggested, to avoid any accidental output ?>
301 Redirect Using ASP
Simply add this code to your page or script:
<%@ Language=VBScript %> <% Response.Status="301 Moved Permanently" Response.AddHeader "Location", "http://www.new-url.com/" %>
301 Redirect Using ASP .NET
Simply add this code to your page or script:
<script runat="server"> private void Page_Load(object sender, System.EventArgs e) { Response.Status = "301 Moved Permanently"; Response.AddHeader("Location","http://www.new-url.com/"); } </script>
301 Redirect Using JSP/JAVA
Simply add this code to your page or script:
<% response.setStatus(301); response.setHeader( "Location", "http://www.new-url.com/" ); response.setHeader( "Connection", "close" ); %>
301 Redirect Using CGI/PERL
Simply add this code to your cgi/perl script:
$q = new CGI; print $q->redirect(" http://www.new-url.com/ ");
301 Redirect Using Ruby/Ruby on Rails
Simply add this code to your ruby/ruby on rails script:
head :moved_permanently, :location => "http://www.domain.com/
Zachary Pinter has a nice explanation of this.
Pleaee note that all of the snippets of code above are examples and I have tested each at some point. However, I am in no way responsible for any damage the code may cause, you use this code at your own risk.
发表评论
-
关于sojo输出json中出现~unique-id~字样的问题
2010-07-20 10:27 3078问题:在项目中,问题的表现如下,使用SojoJsonStrin ... -
jquery.form.js ajax上传文件问题
2010-07-20 10:25 4823问题:使用jquery.form.js实现ajax上传文件功能 ... -
Ehcache集群随记
2009-11-10 09:28 1702Distributed Caching with ehcach ... -
ActiveMQ集群随记
2009-11-10 09:28 3919Problem: cluster on JMS queue o ... -
常用第3方类库
2009-11-02 10:47 784转自:http://www.iteye.com/n ... -
项目中一次正则表达式的实践
2009-10-23 17:13 932今天在项目中遇到这样一个需求: 要求把一段HTML代码中的注释 ... -
DateFormat
2009-08-20 17:01 792from http://shib.kuleuven.be/do ... -
A few frequently used SSL commands
2009-08-19 13:13 1112常用导入证书 %JAVA_HOME%\jre\lib\secu ... -
缓存比较笔录
2009-07-29 18:08 987ehcache 比较常用的轻量级缓存框架,是hibernate ... -
CAS单点登录入门使用
2009-07-29 16:34 978单点登录------CAS http://zhyerr.blo ... -
MySQL数据库引擎介绍
2009-07-29 16:28 1700如果你是个赛车手,并 ... -
在Sql Server中使用pst根据字符型类型查询的性能问题
2009-03-23 10:59 951问题:在使用mssqlserver的jdbc时,当根据字符型列 ... -
Ibatis事务的一些小结
2009-03-11 10:33 3105问题发生:原先在使用Ibatis的时候进行insert, up ... -
Ajax应用的安全性小结
2009-02-12 09:47 820对Ajax应用的安全性进行一下小结: 1.基于各浏览器的ser ... -
如何防止SQL注入
2009-02-10 10:05 4080归纳一下,主要有以下几点: 1.永远不要信任用户的输入。对用户 ... -
How to make thread safe
2009-01-11 16:39 940How to make thread safe 1.Use i ... -
Java怎样中断一个运行中的线程
2009-01-09 10:15 999程序是很简易的。然而,在编程人员面前,多线程呈现出了一组新的难 ... -
Apache整合Tomcat后get方式提交中文乱码问题解决
2009-01-08 11:34 2637我在Tomcat中的8080的connector里配置了URI ... -
Quartz 与 Spring 配置注意事项
2008-08-29 18:05 1439在Spring配置和Quartz集成内容时,有两点需要注意 1 ... -
GLASSFISH 的里里外外
2008-07-13 15:13 1216GlassFish 有很广大的用户,仅仅一年之内就有4.5万次 ...
相关推荐
选择一个已存在的目录作为当前工作目录,在其下创建a/b/c/d这样的子目录结构并在这些子目录 的不同层级生成50个普通文件,要求文件名由随机4个小写字母构成。 将a目录下所有内容复制到当前工作目录dst目录下去,...
行业教育软件-学习软件-佳文习题软件 2.0.zip
漆佳文的成绩.py
欲写佳文觅亮点作文.doc
2021年医德医风个人总结佳文.docx
佳文科技网络通讯协议图屏幕保护程序
班组长培训的学习总结佳文汇总.doc
妙用古诗,巧铸佳文作文课件.ppt
制作LRC的高效的工具。是速配歌词独立自主开发的lrc歌词编辑器,该软件吸收了各Lrc歌词编辑器的优点,同时开发更多新功能,让老用户感觉更亲切,让新用户更容易上手。
制作LRC的高效的工具。是速配歌词独立自主开发的Lrc歌词编辑器,该软件吸收了各Lrc歌词编辑器的优点,同时开发更多新功能,让老用户感觉更亲切,让新用户更容易上手。 软件截图一 ... 软件截图二
1、支持多种知识呈现方式:文本,表格,树,图片,网页。 2、支持多种编程语言的高亮显示:Delphi、Java、C++、C#、SQL等。高亮显示方式可以设定。 3、支持知识全文搜索功能。可以搜索到网页、文本、表格、树中的...
Linux Socket编程学习必备佳文
密蒙花总黄酮对去势雄鼠干眼症泪腺TGF-β1及其基因表达的影响,陈佳文,彭清华,目的 观察密蒙花总黄酮对去势导致干眼症雄鼠泪腺TGF-β1及其基因表达的影响,探讨密蒙花总黄酮治疗干眼症的机制。方法 健康1mo Wistar...
行业教育软件-学习软件-佳用成人本科英语三级真题练习系统 1.0 (1).zip
北京:机械工业出版社,2005 [5]李光飞,胡佳文.单片机课程设计实例指导.北京:北京航空航天大学出版社,2004 如需要代码及电路图(Proteus仿真图)请联系QQ:627733894 ----------------------- 基于AT89C51单片机...
板翅式换热器工艺攻关类型,用于板翅式换热器设计、工艺、及管理人员学习和指导工作用。该文章思路清晰,内容详实、参数精准。特别是对航工换热器的设计及工艺编制具有很好的指导意义,是难得的一篇佳文。
前端资源合集引自目录css处理图片压缩/合并在线制作转换工具项目管理版本控制检测/测试多终端检查/测试兼容/性能/数据查询性能测试综合其他代码...技术刊物公众号微博号前端设计综合活动、会议活动会议佳文选摘编程人
新托福写作王是一款...写作能力的提高过程就是不断集众家之所长,不断吸收消化佳文妙句的过程。本模块提供了超全的必备精彩写作资料:综合写作独立写作模板大全、ETS分类题库、写作思路及几百篇满分范文、写作经典句