简体   繁体   English

经典的asp response.redirect到适当的页面

[英]classic asp response.redirect to appropriate page

I created a .html maintenance file and I want when someone goes to the site to redirect to the maintenance folder/index.html 我创建了一个.html维护文件,并且希望有人访问该网站时将其重定向到维护文件夹/index.html。

my code: (default.asp at the root) 我的代码:(位于根目录下的default.asp)

<%
   If InStr( UCase(Request.ServerVariables("SERVER_NAME")),  UCase("abc.com") ) > 0   Then 
       Response.Redirect("/maintenance/")      
   ElseIf InStr( UCase(Request.ServerVariables("SERVER_NAME")),  UCase("web.com") ) > 0 Then 
       Response.Redirect("/web/") 
   End If

 %>

it works fine, if I go to abc.com but if I type in abc.com/blog it goes to the blog page. 它可以正常工作,如果我转到abc.com,但是如果我输入abc.com/blog,则转到博客页面。 how do I prevent so it doesn't go to any sub folders. 我该如何防止它不会进入任何子文件夹。

Maybe using Request.ServerVariables["HTTP_HOST"] can solve your problem. 也许使用Request.ServerVariables["HTTP_HOST"]可以解决您的问题。

Have you tried to look in the variable Request.ServerVariables("SERVER_NAME") with a Response.Write in order to see why the check on the string fails? 您是否尝试过使用带有Response.Write的变量Request.ServerVariables("SERVER_NAME")来查看为什么对字符串的检查失败?

Are you using this "test > do" method instead of just taking the site down and creating a custom 404.html page because: (1) Your site receives calls via various domain names and you want some to work but not others; 您是在使用这种“测试>做”方法,而不是只是因为关闭网站并创建自定义的404.html页面,原因是:(1)您的网站通过各种域名接收呼叫,并且您希望某些域名可以工作,而其他域名则无法工作; or (2) You just didn't think of using the 404 method? 或(2)您只是没想到要使用404方法?

Anyway, if you want to do it via code, then put this at the very top (before header-very important) of a page or even use this AS your index.asp or default.asp page: 无论如何,如果您想通过代码来执行此操作,请将其放在页面的最顶部(非常重要的标题之前),或者甚至将此AS用作index.asp或default.asp页面:

<%
s_url = Request.ServerVariables("server_name")
s_url = lcase(s_url)
b_found = InStr(1,s_url, "abc.com",1)
if (b_found <> 0) then
    response.redirect("/maintenance/")
end if
%>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM