前面提到了用.htaccess做301重定向,现在又收集了很多重定向的代码,如果主机不支持.htaccess,可以选用下方的方法:
1、IIS下301设置
Internet信息服务管理器 -> 虚拟目录 -> 重定向到URL,输入需要转向的目标URL,并选择“资源的永久重定向”。
2、ASP下的301转向代码
ASP/Visual Basic代码
- <%@ Language=VBScript %>
- <%
- Response.Status=”301 Moved Permanently”
- Response.AddHeader “Location”, “http://www.wuleilei.com/articles/301/”
- %>
3、ASP.Net下的301转向代码
C#代码
- <script runat=”server”>
- private void Page_Load(object sender, System.EventArgs e)
- {
- Response.Status = “301 Moved Permanently”;
- Response.AddHeader(”Location”,”http:
- }
- </script>
4、PHP下的301转向代码
PHP代码
- header(”HTTP/1.1 301 Moved Permanently”);
- header(”Location: http:
- exit();
5、CGI Perl下的301转向代码
C++代码
- $q = new CGI;
- print $q->redirect(”http:
6、JSP下的301转向代码
Java代码
- <%
- response.setStatus(301);
- response.setHeader( “Location”, “http:
- response.setHeader( “Connection”, “close” );
- %>
可以在下面的网站检测是否301转向成功:
http://www.seobox.org/getheader.htm
本站原创,转载请标明:来自追梦博客(http://www.wuleilei.com/)
本文地址:http://www.wuleilei.com/Blog/240
白
JankoAtWarpSpeed对...