首页 > 分享转载 > ASP代码简单实现 PJBlog 301重定向

ASP代码简单实现 PJBlog 301重定向

为了记录,以后也可借鉴用。虽然我们可以使用 httpd.ini 简单实现301重定向,但是大部分 PJBlog 使用的虚拟主机并不支持 rewrite,所以就没有办法使用此方法了,其实我们可以使用 ASP代码简单实现 PJBlog 的301重定向的。

我用过很多的虚拟主机虽然支持伪静态,但是不支持301重定向,现在这个合租的也是这样(其实就他们说是合租的,说不定也是个虚拟主机)。

'301重定向
dim Is301
Is301 = 1    '301开关
if Is301 = 1 then
  Dim ScriptAddress, NewDomain
  NewDomain = "http://imluren.com"   '你的博客地址
  GetDomain = "http://"&Lcase(Request.ServerVariables("Server_Name"))   '当前地址
  ScriptAddress = Lcase(Request.ServerVariables("SCRIPT_NAME"))   '路径及文件名
  qs=Lcase(Request.QueryString)   '参数
  if qs<>"" then ScriptAddress = ScriptAddress & “?” & qs   '路径及文件名+参数
  if GetDomain<>NewDomain then   '301重定向
    Response.Status="301 Moved Permanently"
    Response.AddHeader "Location",NewDomain & ScriptAddress
    Response.End
  end if
end if

还有 httpd.ini 重定向方式也记录下(IIS5.1+rewrite2.x 环境测试成功):

# For ISAPI_Rewrite 2.x
RewriteCond Host: ^imluren\.com$
RewriteRule (.*) http\://www\.imluren\.com$1 [I,RP]

# For ISAPI_Rewrite 3.x
RewriteCond %{HTTP:Host} ^imluren\.com$
RewriteRule (.*) http\://www\.imluren\.com$1 [NC,R=301]

———— 本文部分引用自:http://bbs.pjhome.net/

  1. 还没有评论
评论提交中, 请稍候...