Strip Query String from url

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Scott

    Strip Query String from url

    Below is a script I use to strip everything from a url except the actual
    page. So for example, "http://www.cnn.com/mypage.asp?arti cle=5&id=20"
    becomes "mypage.asp ".

    I'm looking for a script that will strip any querystring from a url if it
    exists, so my result would be "http://www.cnn.com/mypage.asp".

    Can someone help me modify my script below to achieve this result? I'm
    horrible with string functions.


    CODE to Get URL **************

    Right(Request.S erverVariables( "SCRIPT_NAME"), Len(Request.Ser verVariables("S CRIPT_NAME"))-InStrRev(Reques t.ServerVariabl es("SCRIPT_NAME "),"/"))


  • Evertjan.

    #2
    Re: Strip Query String from url

    Scott wrote on 03 sep 2006 in microsoft.publi c.inetserver.as p.general:
    "http://www.cnn.com/mypage.asp?arti cle=5&id=20"
    >
    I'm looking for a script that will strip any querystring from a url if
    it exists, so my result would be "http://www.cnn.com/mypage.asp".
    <% 'vbscript
    t = "http://www.cnn.com/mypage.asp"
    response.write stripFromQmark( t)
    %>

    <script runat='server' language='jscri pt'>
    function stripFromQmark( x){
    return x.replace(/\?.*/,'')
    }
    </script>

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)

    Comment

    • McKirahan

      #3
      Re: Strip Query String from url

      "Scott" <sbailey@milesl umber.comwrote in message
      news:#M2uWU4zGH A.4116@TK2MSFTN GP02.phx.gbl...
      Below is a script I use to strip everything from a url except the actual
      page. So for example, "http://www.cnn.com/mypage.asp?arti cle=5&id=20"
      becomes "mypage.asp ".
      >
      I'm looking for a script that will strip any querystring from a url if it
      exists, so my result would be "http://www.cnn.com/mypage.asp".
      >
      Can someone help me modify my script below to achieve this result? I'm
      horrible with string functions.
      >
      >
      CODE to Get URL **************
      >
      >
      Right(Request.S erverVariables( "SCRIPT_NAME"), Len(Request.Ser verVariables("S C
      RIPT_NAME"))-InStrRev(Reques t.ServerVariabl es("SCRIPT_NAME "),"/"))


      Dim strRSV
      strRSV = Request.ServerV ariables("SCRIP T_NAME")
      Dim strURL
      strURL = Left(strRSV,InS tr(strRSV,"?") -1)


      Comment

      • Scott

        #4
        Re: Strip Query String from url

        Thank you.

        "McKirahan" <News@McKirahan .comwrote in message
        news:xL2dnd8Ezf H722bZnZ2dnUVZ_ tednZ2d@comcast .com...
        "Scott" <sbailey@milesl umber.comwrote in message
        news:#M2uWU4zGH A.4116@TK2MSFTN GP02.phx.gbl...
        >Below is a script I use to strip everything from a url except the actual
        >page. So for example, "http://www.cnn.com/mypage.asp?arti cle=5&id=20"
        >becomes "mypage.asp ".
        >>
        >I'm looking for a script that will strip any querystring from a url if it
        >exists, so my result would be "http://www.cnn.com/mypage.asp".
        >>
        >Can someone help me modify my script below to achieve this result? I'm
        >horrible with string functions.
        >>
        >>
        >CODE to Get URL **************
        >>
        >>
        Right(Request.S erverVariables( "SCRIPT_NAME"), Len(Request.Ser verVariables("S C
        RIPT_NAME"))-InStrRev(Reques t.ServerVariabl es("SCRIPT_NAME "),"/"))
        >
        >
        Dim strRSV
        strRSV = Request.ServerV ariables("SCRIP T_NAME")
        Dim strURL
        strURL = Left(strRSV,InS tr(strRSV,"?") -1)
        >
        >

        Comment

        • Anthony Jones

          #5
          Re: Strip Query String from url


          "Scott" <sbailey@milesl umber.comwrote in message
          news:%23M2uWU4z GHA.4116@TK2MSF TNGP02.phx.gbl. ..
          Below is a script I use to strip everything from a url except the actual
          page. So for example, "http://www.cnn.com/mypage.asp?arti cle=5&id=20"
          becomes "mypage.asp ".
          >
          I'm looking for a script that will strip any querystring from a url if it
          exists, so my result would be "http://www.cnn.com/mypage.asp".
          >
          Can someone help me modify my script below to achieve this result? I'm
          horrible with string functions.
          >
          >
          CODE to Get URL **************
          >
          >
          Right(Request.S erverVariables( "SCRIPT_NAME"), Len(Request.Ser verVariables("S C
          RIPT_NAME"))-InStrRev(Reques t.ServerVariabl es("SCRIPT_NAME "),"/"))
          >
          >
          The SCRIPT_NAME server variable does not contain query string. Nor does it
          contain protocol or host name it only contains the absolute virtual path to
          the script.



          Comment

          • Dave Anderson

            #6
            Re: Strip Query String from url

            Scott wrote:
            Below is a script I use to strip everything from a url
            except the actual page. So for example,
            "http://www.cnn.com/mypage.asp?arti cle=5&id=20" becomes
            "mypage.asp ".
            If you intend this for a link, simply use this:

            <a href="<%=Reques t.ServerVariabl es("URL")%>".. . </a>

            No need to parse anything.




            --
            Dave Anderson

            Unsolicited commercial email will be read at a cost of $500 per message. Use
            of this email address implies consent to these terms.


            Comment

            • Evertjan.

              #7
              Re: Strip Query String from url

              Dave Anderson wrote on 04 sep 2006 in
              microsoft.publi c.inetserver.as p.general:
              Scott wrote:
              >Below is a script I use to strip everything from a url
              >except the actual page. So for example,
              >"http://www.cnn.com/mypage.asp?arti cle=5&id=20" becomes
              >"mypage.asp" .
              >
              If you intend this for a link, simply use this:
              >
              <a href="<%=Reques t.ServerVariabl es("URL")%>".. . </a>
              >
              No need to parse anything.
              Certainly, but is it useful to link tot the page itself?


              --
              Evertjan.
              The Netherlands.
              (Please change the x'es to dots in my emailaddress)

              Comment

              • Dave Anderson

                #8
                Re: Strip Query String from url

                Evertjan. wrote:
                Certainly, but is it useful to link tot the page itself?
                Yes, especially when the querystring has session-related nonsense in it,
                such as the way youtube embeds the search query in subsequent links. Perhaps
                I should have written it this way:

                <a href="<%=Reques t.ServerVariabl es("URL")%>">Pe rmalink</a>




                --
                Dave Anderson

                Unsolicited commercial email will be read at a cost of $500 per message. Use
                of this email address implies consent to these terms.


                Comment

                • Evertjan.

                  #9
                  Re: Strip Query String from url

                  Dave Anderson wrote on 04 sep 2006 in
                  microsoft.publi c.inetserver.as p.general:
                  Evertjan. wrote:
                  >Certainly, but is it useful to link tot the page itself?
                  >
                  Yes, especially when the querystring has session-related nonsense in
                  it, such as the way youtube embeds the search query in subsequent
                  links. Perhaps I should have written it this way:
                  >
                  <a href="<%=Reques t.ServerVariabl es("URL")%>">Pe rmalink</a>
                  Yes. I see some sense in an inc file with:

                  <form
                  action = '<%=Request.Ser verVariables("U RL")%>'
                  method = 'get'
                  >
                  ....

                  --
                  Evertjan.
                  The Netherlands.
                  (Please change the x'es to dots in my emailaddress)

                  Comment

                  Working...