URL rewriting with ASP

Discussion in 'ASP General' started by daddywhite, Jul 28, 2007.

  1. daddywhite

    daddywhite Guest

    I need to rewrite a URL like:

    FROM: /mypage.asp?my_id=78

    TO: /contact-us

    Where contact us is the name of that page stored ion a database.

    I can easily use a ISAPI filter to change it to:

    /page/78/contact-us

    HOWEVER i do not want the "78" in the URL. The reason for this is that
    site is already established under names like "/contact-us" as it was
    done is .net somehow.

    Anyway of doing this in ASP?

    I had the idea of physically creating the folder "/contact-us" using
    the FSO and thendropping in an index file which searched the database
    for the ID based on the name of the page, then set a session based on
    that ID and then did a server.transfer to the "mypage.asp" and changed
    that page to look for the session rather than the querystring.

    Just wondering if anyone has a neater way?

    Regards and thanks for your time.

    Dave.
    daddywhite, Jul 28, 2007
    #1
    1. Advertising

  2. "daddywhite" <> wrote in message
    news:...
    > I need to rewrite a URL like:
    >
    > FROM: /mypage.asp?my_id=78
    >
    > TO: /contact-us
    >
    > Where contact us is the name of that page stored ion a database.
    >
    > I can easily use a ISAPI filter to change it to:
    >
    > /page/78/contact-us
    >
    > HOWEVER i do not want the "78" in the URL. The reason for this is that
    > site is already established under names like "/contact-us" as it was
    > done is .net somehow.
    >
    > Anyway of doing this in ASP?
    >
    > I had the idea of physically creating the folder "/contact-us" using
    > the FSO and thendropping in an index file which searched the database
    > for the ID based on the name of the page, then set a session based on
    > that ID and then did a server.transfer to the "mypage.asp" and changed
    > that page to look for the session rather than the querystring.
    >
    > Just wondering if anyone has a neater way?
    >
    > Regards and thanks for your time.
    >


    Dave,

    I'm finding it a little bit confusing to follow what effect you are really
    after. It seems to be an unusual direction, normally one takes a
    non-existant url such as /contact-us and re-writes it to a specific one like
    /mypage.asp?my_id=78 for actual processing. What you seem to be asking for
    is the other way round, is that correct?

    You indicate that currently /contact-us doesn't physically exist. What do
    you expect to happen when you attempt to re-write the URL to /custom-us?

    If you need to pass on info to whatever processes the /custom-us URL such as
    the user ID you can have your ISAPI filter add a custom header to the
    request.

    --
    Anthony Jones - MVP ASP/ASP.NET
    Anthony Jones, Jul 29, 2007
    #2
    1. Advertising

  3. daddywhite

    daddywhite Guest

    yes, "/contact-us" does not exist and I wish oit to re-write to the "/
    mypage.asp?id=78"

    The only way I have it done is using a ISAPI filter but that requires
    that the id "78" or whatever is in the URL to be re-written

    eg: "/78/contact-us"

    HOWEVER i do not wish to have the "78" there - the reason for this is
    that the website is already established and therefore the SEO links
    are already looking at "/contact-us" - I want to keep this
    functionality so as to not affect the SEO rankings. PLUS the client
    wishes keep it this way.

    The only way I have found is using custom 404 errors to extract the
    "contact-us", look in the database for this title in order to find the
    id of the page, then set a session equal to the ID then
    server.transfer to the "mypage.asp"

    This make sense?
    daddywhite, Jul 29, 2007
    #3
  4. daddywhite

    toudidel Guest

    you can do it overwriting 404 http error

    --
    td
    www.uddi.pl
    toudidel, Jul 29, 2007
    #4
  5. daddywhite

    daddywhite Guest

    anyone got a slightly more useful and indepth answer?

    thanks in advance

    regards
    dave
    daddywhite, Jul 29, 2007
    #5
  6. "daddywhite" <> wrote in message
    news:...
    > yes, "/contact-us" does not exist and I wish oit to re-write to the "/
    > mypage.asp?id=78"
    >
    > The only way I have it done is using a ISAPI filter but that requires
    > that the id "78" or whatever is in the URL to be re-written
    >
    > eg: "/78/contact-us"
    >
    > HOWEVER i do not wish to have the "78" there - the reason for this is
    > that the website is already established and therefore the SEO links
    > are already looking at "/contact-us" - I want to keep this
    > functionality so as to not affect the SEO rankings. PLUS the client
    > wishes keep it this way.
    >
    > The only way I have found is using custom 404 errors to extract the
    > "contact-us", look in the database for this title in order to find the
    > id of the page, then set a session equal to the ID then
    > server.transfer to the "mypage.asp"
    >
    > This make sense?
    >


    It's getting closer but still a little muddy.

    I take it that if the "78" in all this is some kind of user ID or some other
    data which may vary.

    In that case if you want the existing URL to remain simpy "/contact-us" then
    where would the ID value be held? A cookie? Session variable? or something
    else?

    --
    Anthony Jones - MVP ASP/ASP.NET
    Anthony Jones, Jul 29, 2007
    #6
  7. daddywhite

    daddywhite Guest

    On 29 Jul, 16:00, "Anthony Jones" <> wrote:
    > "daddywhite" <> wrote in message
    >
    > news:...
    >
    >
    >
    >
    >
    > > yes, "/contact-us" does not exist and I wish oit to re-write to the "/
    > > mypage.asp?id=78"

    >
    > > The only way I have it done is using a ISAPI filter but that requires
    > > that the id "78" or whatever is in the URL to be re-written

    >
    > > eg: "/78/contact-us"

    >
    > > HOWEVER i do not wish to have the "78" there - the reason for this is
    > > that the website is already established and therefore the SEO links
    > > are already looking at "/contact-us" - I want to keep this
    > > functionality so as to not affect the SEO rankings. PLUS the client
    > > wishes keep it this way.

    >
    > > The only way I have found is using custom 404 errors to extract the
    > > "contact-us", look in the database for this title in order to find the
    > > id of the page, then set a session equal to the ID then
    > > server.transfer to the "mypage.asp"

    >
    > > This make sense?

    >
    > It's getting closer but still a little muddy.
    >
    > I take it that if the "78" in all this is some kind of user ID or some other
    > data which may vary.
    >
    > In that case if you want the existing URL to remain simpy "/contact-us" then
    > where would the ID value be held? A cookie? Session variable? or something
    > else?
    >
    > --
    > Anthony Jones - MVP ASP/ASP.NET- Hide quoted text -
    >
    > - Show quoted text -


    EXACLTY, that is the question I am asking. I assume a session
    variable.

    The 78 refers to the Id of the page held in the database.

    I see lots of websites with /contact-us which are obviously database
    driven - just wondering the best way to do this in ASP

    see bbrail.com for example
    daddywhite, Jul 29, 2007
    #7
  8. daddywhite wrote:
    > On 29 Jul, 16:00, "Anthony Jones" <> wrote:
    >> "daddywhite" <> wrote in message
    >>
    >> news:...
    >>
    >>
    >>
    >>
    >>
    >>> yes, "/contact-us" does not exist and I wish oit to re-write to the
    >>> "/ mypage.asp?id=78"

    >>
    >>> The only way I have it done is using a ISAPI filter but that
    >>> requires that the id "78" or whatever is in the URL to be re-written

    >>
    >>> eg: "/78/contact-us"

    >>
    >>> HOWEVER i do not wish to have the "78" there - the reason for this
    >>> is that the website is already established and therefore the SEO
    >>> links
    >>> are already looking at "/contact-us" - I want to keep this
    >>> functionality so as to not affect the SEO rankings. PLUS the client
    >>> wishes keep it this way.

    >>
    >>> The only way I have found is using custom 404 errors to extract the
    >>> "contact-us", look in the database for this title in order to find
    >>> the
    >>> id of the page, then set a session equal to the ID then
    >>> server.transfer to the "mypage.asp"

    >>
    >>> This make sense?

    >>
    >> It's getting closer but still a little muddy.
    >>
    >> I take it that if the "78" in all this is some kind of user ID or
    >> some other data which may vary.
    >>
    >> In that case if you want the existing URL to remain simpy
    >> "/contact-us" then where would the ID value be held? A cookie?
    >> Session variable? or something else?
    >>
    >> --
    >> Anthony Jones - MVP ASP/ASP.NET- Hide quoted text -
    >>
    >> - Show quoted text -

    >
    > EXACLTY, that is the question I am asking. I assume a session
    > variable.
    >
    > The 78 refers to the Id of the page held in the database.
    >


    If the id is in a session variable, what is it doing in the url?

    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"
    Bob Barrows [MVP], Jul 29, 2007
    #8
  9. "daddywhite" <> wrote in message
    news:...
    > On 29 Jul, 16:00, "Anthony Jones" <> wrote:
    > > "daddywhite" <> wrote in message
    > >
    > > news:...
    > >
    > >
    > > > yes, "/contact-us" does not exist and I wish oit to re-write to the "/
    > > > mypage.asp?id=78"

    > >
    > > > The only way I have it done is using a ISAPI filter but that requires
    > > > that the id "78" or whatever is in the URL to be re-written

    > >
    > > > eg: "/78/contact-us"

    > >
    > > > HOWEVER i do not wish to have the "78" there - the reason for this is
    > > > that the website is already established and therefore the SEO links
    > > > are already looking at "/contact-us" - I want to keep this
    > > > functionality so as to not affect the SEO rankings. PLUS the client
    > > > wishes keep it this way.

    > >
    > > > The only way I have found is using custom 404 errors to extract the
    > > > "contact-us", look in the database for this title in order to find the
    > > > id of the page, then set a session equal to the ID then
    > > > server.transfer to the "mypage.asp"

    > >
    > > > This make sense?

    > >
    > > It's getting closer but still a little muddy.
    > >
    > > I take it that if the "78" in all this is some kind of user ID or some

    other
    > > data which may vary.
    > >
    > > In that case if you want the existing URL to remain simpy "/contact-us"

    then
    > > where would the ID value be held? A cookie? Session variable? or

    something
    > > else?
    > >
    > > --
    > > Anthony Jones - MVP ASP/ASP.NET- Hide quoted text -
    > >
    > > - Show quoted text -

    >
    > EXACLTY, that is the question I am asking. I assume a session
    > variable.
    >
    > The 78 refers to the Id of the page held in the database.
    >


    Ok still trying to demystify your requirement. I think your in a situation
    where depending on the context of the current user session a visit to
    /contact-us is expected to generate different results. An ID is to be
    associated with the users session that specifies that content. I doubt I
    have that right but in case I do:-

    Store the ID in the Session object, use the 404 kludge, test that
    /content-us is being requested, server.transfer to mypage.asp and have
    mypage.asp retrieve the value its interested in from the session object.

    Alternatively get the ISAPI filter to re-write the url to mypage.asp which
    can still retrieve the ID from the session object.

    --
    Anthony Jones - MVP ASP/ASP.NET
    Anthony Jones, Jul 29, 2007
    #9
  10. daddywhite

    daddywhite Guest

    On 29 Jul, 17:26, "Anthony Jones" <> wrote:
    > "daddywhite" <> wrote in message
    >
    > news:...
    >
    >
    >
    >
    >
    > > On 29 Jul, 16:00, "Anthony Jones" <> wrote:
    > > > "daddywhite" <> wrote in message

    >
    > > >news:...

    >
    > > > > yes, "/contact-us" does not exist and I wish oit to re-write to the "/
    > > > > mypage.asp?id=78"

    >
    > > > > The only way I have it done is using a ISAPI filter but that requires
    > > > > that the id "78" or whatever is in the URL to be re-written

    >
    > > > > eg: "/78/contact-us"

    >
    > > > > HOWEVER i do not wish to have the "78" there - the reason for this is
    > > > > that the website is already established and therefore the SEO links
    > > > > are already looking at "/contact-us" - I want to keep this
    > > > > functionality so as to not affect the SEO rankings. PLUS the client
    > > > > wishes keep it this way.

    >
    > > > > The only way I have found is using custom 404 errors to extract the
    > > > > "contact-us", look in the database for this title in order to find the
    > > > > id of the page, then set a session equal to the ID then
    > > > > server.transfer to the "mypage.asp"

    >
    > > > > This make sense?

    >
    > > > It's getting closer but still a little muddy.

    >
    > > > I take it that if the "78" in all this is some kind of user ID or some

    > other
    > > > data which may vary.

    >
    > > > In that case if you want the existing URL to remain simpy "/contact-us"

    > then
    > > > where would the ID value be held? A cookie? Session variable? or

    > something
    > > > else?

    >
    > > > --
    > > > Anthony Jones - MVP ASP/ASP.NET- Hide quoted text -

    >
    > > > - Show quoted text -

    >
    > > EXACLTY, that is the question I am asking. I assume a session
    > > variable.

    >
    > > The 78 refers to the Id of the page held in the database.

    >
    > Ok still trying to demystify your requirement. I think your in a situation
    > where depending on the context of the current user session a visit to
    > /contact-us is expected to generate different results. An ID is to be
    > associated with the users session that specifies that content. I doubt I
    > have that right but in case I do:-
    >
    > Store the ID in the Session object, use the 404 kludge, test that
    > /content-us is being requested, server.transfer to mypage.asp and have
    > mypage.asp retrieve the value its interested in from the session object.
    >
    > Alternatively get the ISAPI filter to re-write the url to mypage.asp which
    > can still retrieve the ID from the session object.
    >
    > --
    > Anthony Jones - MVP ASP/ASP.NET- Hide quoted text -
    >
    > - Show quoted text -


    Thanks for your reply
    ===============================
    > Store the ID in the Session object, use the 404 kludge, test that
    > /content-us is being requested, server.transfer to mypage.asp and have
    > mypage.asp retrieve the value its interested in from the session object.

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

    This is exactly what I thought I would need to do.

    I was wondering whether there was any other way - I know about the
    ISAPI filter method but that would require the ID being in the URL
    somewhere.I DO NOT want this to happen.

    One way I figured was:

    1) "/contact-us"
    2) ISAPI rewrites this to "mypage.asp" passing "contact-us" as a
    querystring
    3) "mypage.asp" looks in database for "contact-us" and then displayed
    the relevant page content
    4) alternatively on the "mypage.asp" if the querystring returns
    "*.asp" then server.transfer to that ASP page. (cos not all of the
    websites pages are dynamic database driven)

    Does this make sense as to what I am tring to do?

    Unless I can use the ISAPI filter to only kick in when ".asp" is NOT
    found in the URL of course.

    Apologies if I am/was not making sense - its quite hard to explain
    what I am trying to acheive.
    daddywhite, Jul 29, 2007
    #10
  11. "daddywhite" <> wrote in message
    news:...
    > On 29 Jul, 17:26, "Anthony Jones" <> wrote:
    > > "daddywhite" <> wrote in message
    > >
    > > news:...
    > >
    > >
    > >
    > >
    > >
    > > > On 29 Jul, 16:00, "Anthony Jones" <> wrote:
    > > > > "daddywhite" <> wrote in message

    > >
    > > > >news:...

    > >
    > > > > > yes, "/contact-us" does not exist and I wish oit to re-write to

    the "/
    > > > > > mypage.asp?id=78"

    > >
    > > > > > The only way I have it done is using a ISAPI filter but that

    requires
    > > > > > that the id "78" or whatever is in the URL to be re-written

    > >
    > > > > > eg: "/78/contact-us"

    > >
    > > > > > HOWEVER i do not wish to have the "78" there - the reason for this

    is
    > > > > > that the website is already established and therefore the SEO

    links
    > > > > > are already looking at "/contact-us" - I want to keep this
    > > > > > functionality so as to not affect the SEO rankings. PLUS the

    client
    > > > > > wishes keep it this way.

    > >
    > > > > > The only way I have found is using custom 404 errors to extract

    the
    > > > > > "contact-us", look in the database for this title in order to find

    the
    > > > > > id of the page, then set a session equal to the ID then
    > > > > > server.transfer to the "mypage.asp"

    > >
    > > > > > This make sense?

    > >
    > > > > It's getting closer but still a little muddy.

    > >
    > > > > I take it that if the "78" in all this is some kind of user ID or

    some
    > > other
    > > > > data which may vary.

    > >
    > > > > In that case if you want the existing URL to remain simpy

    "/contact-us"
    > > then
    > > > > where would the ID value be held? A cookie? Session variable? or

    > > something
    > > > > else?

    > >
    > > > > --
    > > > > Anthony Jones - MVP ASP/ASP.NET- Hide quoted text -

    > >
    > > > > - Show quoted text -

    > >
    > > > EXACLTY, that is the question I am asking. I assume a session
    > > > variable.

    > >
    > > > The 78 refers to the Id of the page held in the database.

    > >
    > > Ok still trying to demystify your requirement. I think your in a

    situation
    > > where depending on the context of the current user session a visit to
    > > /contact-us is expected to generate different results. An ID is to be
    > > associated with the users session that specifies that content. I doubt

    I
    > > have that right but in case I do:-
    > >
    > > Store the ID in the Session object, use the 404 kludge, test that
    > > /content-us is being requested, server.transfer to mypage.asp and have
    > > mypage.asp retrieve the value its interested in from the session object.
    > >
    > > Alternatively get the ISAPI filter to re-write the url to mypage.asp

    which
    > > can still retrieve the ID from the session object.
    > >
    > > --
    > > Anthony Jones - MVP ASP/ASP.NET- Hide quoted text -
    > >
    > > - Show quoted text -

    >
    > Thanks for your reply
    > ===============================
    > > Store the ID in the Session object, use the 404 kludge, test that
    > > /content-us is being requested, server.transfer to mypage.asp and have
    > > mypage.asp retrieve the value its interested in from the session object.

    > ===============================
    >
    > This is exactly what I thought I would need to do.
    >
    > I was wondering whether there was any other way - I know about the
    > ISAPI filter method but that would require the ID being in the URL
    > somewhere.I DO NOT want this to happen.
    >
    > One way I figured was:
    >
    > 1) "/contact-us"
    > 2) ISAPI rewrites this to "mypage.asp" passing "contact-us" as a
    > querystring
    > 3) "mypage.asp" looks in database for "contact-us" and then displayed
    > the relevant page content
    > 4) alternatively on the "mypage.asp" if the querystring returns
    > "*.asp" then server.transfer to that ASP page. (cos not all of the
    > websites pages are dynamic database driven)
    >
    > Does this make sense as to what I am tring to do?
    >
    > Unless I can use the ISAPI filter to only kick in when ".asp" is NOT
    > found in the URL of course.
    >
    > Apologies if I am/was not making sense - its quite hard to explain
    > what I am trying to acheive.
    >


    What I think you want keeps changing. It isn't helping that your not
    responding to statements I'm making that don't match what you want.

    Now what I think you want is that there will be a number of different URLs
    referenced in the system which don't actually exist and you want to trap
    those in order to send the appropriate output. Again I still don't think
    I've got it. But in case I have:-

    It sounds like what you are looking for is the 404 trick. However instead
    of the 404 custom handling page transfering to mypage.asp, the 404 custom
    handler _IS_ mypage.asp. Now all the mypage.asp has to do is use the URL
    (already provided in the querystring by IIS on encountering a 404) as a key
    to lookup the content to be sent. This ditched the numeric ID altogether.

    I would avoid writing an ISAPI filter unless it's absolutely necessary.

    Are we getting there?


    --
    Anthony Jones - MVP ASP/ASP.NET
    Anthony Jones, Jul 29, 2007
    #11
  12. daddywhite

    Rob ^_^ Guest

    Hi Dave,

    To hide the location.href values of documents that you present to the user,
    you need to use frames for site navigation and not open documents in their
    own window/tab.
    Here are some snippets from my site

    In my root folder, the start page is set to Index.asp, which can accepte an
    optional parameter 'url'
    <%@ Language="VBSCRIPT" %>
    <%
    dim sURL
    sURL = Request.QueryString("URL")
    if len(sURL)=0 then
    sURL = "Welcome.asp"
    end if
    Session("CurrentPage")="Welcome.asp"


    %>
    ----------------------------------------------
    My Index page is a frames page with two frames

    <frame name="SideMenu" src="main_menu.asp" target="main">
    <frame name="main" src="<%=sURL%>">

    In each page I put the following script

    <SCRIPT LANGUAGE="JavaScript1.2">
    //<!--
    function InitPage()
    {
    if (typeof(PreInit) == 'function') PreInit();
    }
    window.onload = InitPage;

    function PreInit()
    {
    if (top == self)
    location.replace("http://" + document.domain +"/?url=" +
    document.URL.substring("http://".length + 1 + document.domain.length));
    }
    //--></SCRIPT>

    This will test to see if the page has a parent (frame) as it is being
    loaded. If it doesn't it will change the document.location.href value to
    reload the page via the index page eg. http://mydomain.com/apage.asp becomes
    http://mydomain.com/?url=apage.asp, reloading the page in a containing
    frame.

    To the user, the address displayed in the Address bar never changes, the
    current document Title is displayed in IE's title bar.

    Each page has the context menu disabled to stop users using the 'Add to
    Favorites' and 'Properties' options to reveal the true url.

    I place a Add to Favorites and and Email a Friend button on each page to
    replace the built in IE functions

    <script>
    if ((navigator.appVersion.indexOf("MSIE") > 0) &&
    (parseInt(navigator.appVersion) >= 4))
    {
    var sURL = "http://" + document.domain +"/?url=" +
    document.URL.substring("http://".length + 1 + document.domain.length);
    var sText = '<img style="cursor:hand" title="Add page to Favorites"
    border="0" src="http://www.iecustomizer.com/images/FavAdd.gif" align="right"
    hspace="1" vspace="1" width="22" height="22"';
    sText += ' onclick="window.external.AddFavorite(sURL
    ,document.title);">';
    sText += '<a href="mailto:?subject=' + document.title + '&amp;body=This
    URL points to a page on IECustomizer.com that may interest you: ' + sURL +
    '">';
    sText += '<img style="cursor:hand" title="Mail link to a friend"
    border="0" src="http://www.iecustomizer.com/images/MailFriend.gif"
    align="right" hspace="1" vspace="1" width="22" height="22"';
    sText += '></a>';
    document.write(sText);
    }
    </script>

    ///////////////

    The covenets of this is that users can defeat it if they have scripting
    disabled in their browser settings so it is important to use <noscript> tags
    to advise the user to enable scripting in order to use your site.

    I hope this give you some ideas.

    For further examples see msdn2.microsoft.com (see how navigation is
    controled throughout the site using parameters in the form linkid=n)

    Regards.

    "daddywhite" <> wrote in message
    news:...
    >I need to rewrite a URL like:
    >
    > FROM: /mypage.asp?my_id=78
    >
    > TO: /contact-us
    >
    > Where contact us is the name of that page stored ion a database.
    >
    > I can easily use a ISAPI filter to change it to:
    >
    > /page/78/contact-us
    >
    > HOWEVER i do not want the "78" in the URL. The reason for this is that
    > site is already established under names like "/contact-us" as it was
    > done is .net somehow.
    >
    > Anyway of doing this in ASP?
    >
    > I had the idea of physically creating the folder "/contact-us" using
    > the FSO and thendropping in an index file which searched the database
    > for the ID based on the name of the page, then set a session based on
    > that ID and then did a server.transfer to the "mypage.asp" and changed
    > that page to look for the session rather than the querystring.
    >
    > Just wondering if anyone has a neater way?
    >
    > Regards and thanks for your time.
    >
    > Dave.
    >
    Rob ^_^, Jul 29, 2007
    #12
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rocky Moore
    Replies:
    0
    Views:
    2,543
    Rocky Moore
    Sep 15, 2005
  2. Gaurav  Agarwal
    Replies:
    2
    Views:
    710
    Gaurav Agarwal
    Jan 31, 2005
  3. =?Utf-8?B?cmFwaWRkYXRh?=

    url rewriting with no extension in url

    =?Utf-8?B?cmFwaWRkYXRh?=, Nov 1, 2006, in forum: ASP .Net
    Replies:
    8
    Views:
    391
    Flinky Wisty Pomm
    Nov 2, 2006
  4. thoeone

    asp.net url rewriting

    thoeone, Feb 28, 2008, in forum: ASP .Net
    Replies:
    4
    Views:
    447
    theone
    Feb 29, 2008
  5. Toni

    URL Rewriting in ASP.NET

    Toni, May 29, 2008, in forum: ASP .Net
    Replies:
    2
    Views:
    445
Loading...

Share This Page