使用经典ASP的Canonical Redirect显示站点文件夹 [英] Canonical Redirect with classic ASP shows site folder

查看:90
本文介绍了使用经典ASP的Canonical Redirect显示站点文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果指向 http://domain.com ,它将重定向到

If pointed to http://domain.com it redirects to http://www.domain.com/thesite/index.asp which is the actual location. No matter the page, it always appends the actual folder path.

我一直在使用此脚本进行规范的重定向,该脚本包含在每个页面中.

ive been using this script for canonical redirection, included in every page.

 If InStr(Request.ServerVariables("SERVER_NAME"),"www") = 0 Then
   Response.Status="301 Moved Permanently"
   Response.AddHeader "Location","http://www." &_ 
   Request.ServerVariables("HTTP_HOST")&_ 
   Request.ServerVariables("SCRIPT_NAME")
 End if

我在共享主机中有几个站点,每个站点都在其自己的文件夹中.

I have several sites in a shared hosting, each in its own folder.

我该如何预防?

感谢您的帮助

推荐答案

好吧,在进一步挖掘之后,我终于碰到了一个解决方案.事实证明IIS7启用了URL重定向规则,因此可以通过web.config来实现,就像这样

Ok after further diggin' i finally bumped into a solution. Turns out IIS7 had url redirection rules enabled, so this can be accomplished through web.config, like this

<configuration>
 <system.webServer>
  <rewrite>
   <rules>
    <rule name="Redirect to WWW" stopProcessing="true">
      <match url=".*" />
      <conditions>
        <add input="{HTTP_HOST}" pattern="^yoursite.com$" />
      </conditions>
      <action type="Redirect" url="http://www.yoursite.com/{R:0}" redirectType="Permanent" />
    </rule>
  </rules>
</rewrite>

在将它列为ASP.NET解决方案而不是经典ASP之前,我忽略了它. 但这已经解决了.

I overlooked it before cause it was listed as ASP.NET solution, not classic ASP. But there it is, solved.

这篇关于使用经典ASP的Canonical Redirect显示站点文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆