How to change all relative paths in a website???

Discussion in 'ASP General' started by Jeff, Jun 16, 2009.

  1. Jeff

    Jeff Guest

    I have thousands of ASP files and a lot of them use relative paths to
    various folders like an images folder so the path looks from the root
    like "/images/whatever.jpg". Now I have been told that the URL has to
    have a folder at the end such as "whatever.com/mine/" which in effect
    is turning the new root into /mine. That means all my relative paths
    won't work and the only solution I can think of is I have to change
    EVERY file that uses a relative path and either hard code the new "/
    mine/" at the beginning or use an application variable to specify what
    the root is and still hard code that at the beginning of each relative
    path.

    Obviously I don't want to spend the time it would take to hopefully
    find every relative path in every file and make this work. I have
    control of the server so can change IIS.

    Is there a solution that will globally make this works so there aren't
    a ton of changes?
    Jeff, Jun 16, 2009
    #1
    1. Advertising

  2. Jeff

    Evertjan. Guest

    Jeff wrote on 16 jun 2009 in microsoft.public.inetserver.asp.general:

    > I have thousands of ASP files and a lot of them use relative paths to
    > various folders like an images folder so the path looks from the root
    > like "/images/whatever.jpg". Now I have been told that the URL has to
    > have a folder at the end such as "whatever.com/mine/" which in effect
    > is turning the new root into /mine.


    This sounds illogical.

    Unless it is the defaultfile in a directory,
    the filename should be at the end of the URL.


    > That means all my relative paths won't work


    Why?

    Because you have been told, or because it is?

    > and the only solution I can think of is I have to change
    > EVERY file that uses a relative path and either hard code the new "/
    > mine/" at the beginning or use an application variable to specify what
    > the root is and still hard code that at the beginning of each relative
    > path.


    Use

    <base href='/'>

    if your relative point should be the root.

    This is really not an ASP, but a html issue.
    If so it is off topic.

    > Obviously I don't want to spend the time it would take to hopefully
    > find every relative path in every file and make this work. I have
    > control of the server so can change IIS.
    >
    > Is there a solution that will globally make this works so there aren't
    > a ton of changes?


    Please first be clearer on what really happened.
    Did your siteprovider change some settings?



    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
    Evertjan., Jun 16, 2009
    #2
    1. Advertising

  3. Jeff

    Guest

    "Evertjan." wrote:

    > This sounds illogical.
    >
    > Unless it is the defaultfile in a directory,
    > the filename should be at the end of the URL.


    You're right. It is illogical. Let me try to make it a little clearer. The
    website sits on an Intranet and in IIS, it's the Default Web Site. Now to
    have this website accessible to the Internet, there is a server that
    basically has an alias which points to a location on the Intranet website, in
    this case the root /. For some illogical reason, this other server creates
    the alias with a folder after the URL as in "whatever.com/mine/". Probably
    not clear as to any of this but I'll continue.

    So accessing the Intranet website using this new alias, turns the root of
    the website now into /mine instead of /. So all the relative paths of images,
    style sheets, etc. are now looking for a folder above where the new root is.
    For example, this was a valid images path "/images/myimage.gif" but now it
    really needs to be "/mine/images/myimage.gif". I wasn't told this, I
    determined that's why it was failing.

    I was hoping that there was something I'm not thinking of like creating a
    virtual directory or something in IIS that would solve everything immediately
    instead of having to edit every file that has a relative path. The Base Href
    would still require editing all those files, but at least that's only one
    addition rather than multiple changes in a file. But there still has to be an
    easier way.

    And I'm not even going to mention the .NET virtual directory that probably
    has the same problem.

    Hopefully that helps to clear things up. Thanks for replying and I'm hoping
    there is an easy solution.
    , Jun 17, 2009
    #3
  4. Jeff

    Evertjan. Guest

    Adrienne Boswell wrote on 17 jun 2009 in
    microsoft.public.inetserver.asp.general:

    > Gazing into my crystal ball I observed
    > =?Utf-8?B?amVmZmN0ZXN0LWdvb2dsZUB5YWhvby5jb20=?=
    > <> writing in
    > news::
    >
    >> "Evertjan." wrote:
    >>
    >>> This sounds illogical.
    >>>
    >>> Unless it is the defaultfile in a directory,
    >>> the filename should be at the end of the URL.

    >>
    >> You're right. It is illogical. Let me try to make it a little clearer.
    >> The website sits on an Intranet and in IIS, it's the Default Web Site.
    >> Now to have this website accessible to the Internet, there is a server
    >> that basically has an alias which points to a location on the Intranet
    >> website, in this case the root /. For some illogical reason, this
    >> other server creates the alias with a folder after the URL as in
    >> "whatever.com/mine/". Probably not clear as to any of this but I'll
    >> continue.
    >>
    >> So accessing the Intranet website using this new alias, turns the root
    >> of the website now into /mine instead of /. So all the relative paths
    >> of images, style sheets, etc. are now looking for a folder above where
    >> the new root is. For example, this was a valid images path
    >> "/images/myimage.gif" but now it really needs to be
    >> "/mine/images/myimage.gif". I wasn't told this, I determined that's
    >> why it was failing.
    >>
    >> I was hoping that there was something I'm not thinking of like
    >> creating a virtual directory or something in IIS that would solve
    >> everything immediately instead of having to edit every file that has a
    >> relative path. The Base Href would still require editing all those
    >> files, but at least that's only one addition rather than multiple
    >> changes in a file. But there still has to be an easier way.
    >>
    >> And I'm not even going to mention the .NET virtual directory that
    >> probably has the same problem.
    >>
    >> Hopefully that helps to clear things up. Thanks for replying and I'm
    >> hoping there is an easy solution.
    >>

    >
    > I think there is something you can do in IIS - I seem to remember having
    > to do that a long time ago with some IIS server somewhere, but alas, I
    > don't remember what I did.
    >
    > You might want to check in an IIS group, like
    > microsoft.public.inetserver.iis .



    I would catch all nonexisting calls that end up in 404.asp,
    and response.redirect or server.transfer them to the factual url.

    A simple all inclusive solution, if only you prevent the reentry of urls
    that are not available under /mine/, which the below does automagically:

    =================== 404.asp ================

    <%

    qstr = lcase(Request.ServerVariables("QUERY_STRING"))

    if instr(qstr,":80/mine/")=0 then
    p = instr(qstr,":80/")
    url = mid(qstr,P+3)
    server.transfer "/mine/" & url
    end if

    %>

    This is the 404 page, the page you requested does not exist.

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

    Please test and adapt to your own peculiar ;-) situation.

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
    Evertjan., Jun 17, 2009
    #4
  5. Gazing into my crystal ball I observed "Evertjan."
    <> writing in news:Xns9C2DAD9711BC6eejj99@
    194.109.133.242:

    > automagically


    I love that word!

    Usage: My van was automagically turned into a Mercedes!
    Citation: Evertjan

    (trying to get it into Merriam Webster)

    --
    Adrienne Boswell at Home
    Arbpen Web Site Design Services
    http://www.cavalcade-of-coding.info
    Please respond to the group so others can share
    Adrienne Boswell, Jun 17, 2009
    #5
  6. Jeff

    Guest

    "Evertjan." wrote:
    > I would catch all nonexisting calls that end up in 404.asp,
    > and response.redirect or server.transfer them to the factual url.
    >
    > A simple all inclusive solution, if only you prevent the reentry of urls
    > that are not available under /mine/, which the below does automagically:


    That would work great for the relative path files but not for images, style
    sheets, etc. that are within those files.
    , Jun 17, 2009
    #6
  7. Jeff

    Evertjan. Guest

    =?Utf-8?B?amVmZmN0ZXN0LWdvb2dsZUB5YWhvby5jb20=?= wrote on 17 jun 2009 in
    microsoft.public.inetserver.asp.general:

    > "Evertjan." wrote:
    >> I would catch all nonexisting calls that end up in 404.asp,
    >> and response.redirect or server.transfer them to the factual url.
    >>
    >> A simple all inclusive solution, if only you prevent the reentry of
    >> urls that are not available under /mine/, which the below does
    >> automagically:

    >
    > That would work great for the relative path files but not for images,
    > style sheets, etc. that are within those files.


    Oh yes, it works fine for any file redirection,
    as there is no clientside coding involved.

    Requests made to the server are never requested by the browser in a
    "relative" way, the browser always has to resolve the call to an absolute
    URL.

    The server doesn't even know what type of file it sends.
    [Only if it is an asp coded file, the file will be rendered into a
    stream, but that has no influence on the working of my code.]

    I repeat the skipped code part of mine here:
    =================== 404.asp ================
    <%

    qstr = lcase(Request.ServerVariables("QUERY_STRING"))

    if instr(qstr,":80/mine/")=0 then
    p = instr(qstr,":80/")
    url = mid(qstr,P+3)
    server.transfer "/mine/" & url
    end if

    %>

    This is the 404 page, the page you requested does not exist.
    ============================================


    So the url of any file, page, image, styesheet, etc that cannot be found
    is converted to the same url string with /mine/ inserted between the
    domainand the rest of the url, unless the /mine/ was already in it's
    place in the url.




    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
    Evertjan., Jun 18, 2009
    #7
  8. Jeff

    Guest

    "Evertjan." wrote:

    > =================== 404.asp ================
    >
    > <%
    >
    > qstr = lcase(Request.ServerVariables("QUERY_STRING"))
    >
    > if instr(qstr,":80/mine/")=0 then
    > p = instr(qstr,":80/")
    > url = mid(qstr,P+3)
    > server.transfer "/mine/" & url
    > end if
    >
    > %>
    >
    > This is the 404 page, the page you requested does not exist.
    >
    > ============================================


    Thanks for the suggestion but it didn't work in my case. I'm just going to
    bite the bullet and do a search and replace for every "/ and but instead of
    hard coding "/mine/ I'll use an application variable. That way in case it
    ever changes again, I only need to change it in one place. Thanks for the
    help!
    , Jun 19, 2009
    #8
  9. wrote on Fri, 19 Jun 2009 06:09:01 -0700:

    > "Evertjan." wrote:


    >> =================== 404.asp ================


    >> <%


    >> qstr = lcase(Request.ServerVariables("QUERY_STRING"))


    >> if instr(qstr,":80/mine/")=0 then p = instr(qstr,":80/")
    >> url = mid(qstr,P+3)
    >> server.transfer "/mine/" & url end if


    >> %>


    >> This is the 404 page, the page you requested does not exist.


    >> ============================================


    > Thanks for the suggestion but it didn't work in my case. I'm just going
    > to bite the bullet and do a search and replace for every "/ and but
    > instead of hard coding "/mine/ I'll use an application variable. That
    > way in case it ever changes again, I only need to change it in one
    > place. Thanks for the help!


    As that will only work in ASP scripts, setting /mine to an Application Root
    in IIS will achieve the same result (I think). It still won't correct any
    non-ASP references though, such as in HTML, CSS, and Javascript, but as
    these wouldn't be using an application variable there's little you can do
    about those other than a hardcoded replace.

    --
    Dan
    Daniel Crichton, Jun 19, 2009
    #9
  10. Jeff

    Evertjan. Guest

    Daniel Crichton wrote on 19 jun 2009 in
    microsoft.public.inetserver.asp.general:

    > wrote on Fri, 19 Jun 2009 06:09:01 -0700:
    >
    >> "Evertjan." wrote:

    >
    > >> =================== 404.asp ================

    >
    > >> <%

    >
    > >> qstr = lcase(Request.ServerVariables("QUERY_STRING"))

    >
    > >> if instr(qstr,":80/mine/")=0 then p = instr(qstr,":80/")
    > >> url = mid(qstr,P+3)
    > >> server.transfer "/mine/" & url end if

    >
    > >> %>

    >
    > >> This is the 404 page, the page you requested does not exist.

    >
    > >> ============================================

    >
    >> Thanks for the suggestion but it didn't work in my case. I'm just
    >> going to bite the bullet and do a search and replace for every "/
    >> and but instead of hard coding "/mine/ I'll use an application
    >> variable. That way in case it ever changes again, I only need to
    >> change it in one place. Thanks for the help!

    >
    > As that will only work in ASP scripts,


    Sorry, what do you mean?

    The above is an asp script, and it only needs to be in entered in a
    dedicated 404.asp page. [the use of such 404.asp page needs to be set in
    IIS, of course]

    Then it will work for .jpg, for .pdf, for .asp, for .html, etc.

    If it "does not work" as expected the OP could please say what it does
    not do.

    You could try response.redirect in stead of server.transfer.

    Did you try?


    > setting /mine to an Application
    > Root in IIS will achieve the same result (I think).


    could be.

    > It still won't


    Please take out the "still"

    > correct any non-ASP references though, such as in HTML, CSS, and
    > Javascript, but as these wouldn't be using an application variable
    > there's little you can do about those other than a hardcoded replace.





    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
    Evertjan., Jun 19, 2009
    #10
    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. Kathy Burke
    Replies:
    0
    Views:
    518
    Kathy Burke
    Nov 14, 2003
  2. Curt_C [MVP]

    Re: Relative Paths

    Curt_C [MVP], May 25, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    355
    =?Utf-8?B?QW5kcmV3IFdpZWQ=?=
    May 26, 2004
  3. terrorix

    Re: Relative Paths

    terrorix, May 26, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    371
    terrorix
    May 26, 2004
  4. Noah
    Replies:
    5
    Views:
    777
  5. Ohad Lutzky

    Paths, gentleman, paths

    Ohad Lutzky, Nov 6, 2006, in forum: Ruby
    Replies:
    2
    Views:
    187
    David Vallner
    Nov 7, 2006
Loading...

Share This Page