자료/ASP

웹 url에 www가 붙지 않은 주소에 www 붙이기

네오블루 2009. 9. 18. 14:32

=====이 소스는 ASP소스입니다=====

=================================

 

소스를 보면 간단하지만...

 

이것 땜시롱 공들였던 노력을 생각하면.....으~~~ 해서 올린다.

 

--index.html--

<html>
<head>
</head>
<frameset rows="100%,*">
 <frame src="index.asp" name="main1">
 <frame src="">
</frameset>
</html>

 

 

--index.asp--

<%
   Dim header, sheader,strRedirectURL
   header = Left(Request.ServerVariables("HTTP_REFERER"),10)
   sheader = "http://www"
 
   If header <> sheader Then
 %>
     <html>
    <head>
    <script language="javascript">
      function on_load()
      {
        parent.location.href="http://www.naver.co.kr";
      }
     </script>
    </head>
 <body onload="javascript:on_load();">
 </body>
 </html>
  
 <%
  Else
     response.redirect "default.asp"
  End If
 %>

 

 

--------------------------------------------------

1. iis 시작 페이지를 index.html 등록한다.
2. index.html이 시작하면 index.asp 페이지가 시작된다.
3. Request.ServerVariables("HTTP_REFERER")  --> 그 이전 페이지이 URL을 나타낸다
4. URL이 www.naver.co.kr 인지 naver.co.kr인지 확인하여 if절이 시작된다.
5. naver.co.kr의 URL은 다시 한번 www.naver.co.kr를 다시 호출(?)한다.
    여기서 parent를 꼭 넣어주어야한다.
    이유는 index.html이 frame으로 나뉘어 있기 때문에 그냥 주소를 호출하면 URL이 변경되지 않고 그 페이지만 refresh된다.