Canonical Redirect with classic ASP shows site folder

匆匆过客 提交于 2020-07-09 17:03:20

问题


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.

How can i prevent this?

Thanx for your help


回答1:


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>

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



来源:https://stackoverflow.com/questions/16637814/canonical-redirect-with-classic-asp-shows-site-folder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!