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

J

Jeff

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?
 
E

Evertjan.

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?
 
J

jeffctest-google

Evertjan. said:
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.
 
E

Evertjan.

Adrienne Boswell wrote on 17 jun 2009 in
microsoft.public.inetserver.asp.general:
Gazing into my crystal ball I observed
=?Utf-8?B?amVmZmN0ZXN0LWdvb2dsZUB5YWhvby5jb20=?=


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.
 
A

Adrienne Boswell

automagically

I love that word!

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

(trying to get it into Merriam Webster)
 
J

jeffctest-google

Evertjan. said:
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.
 
E

Evertjan.

=?Utf-8?B?amVmZmN0ZXN0LWdvb2dsZUB5YWhvby5jb20=?= wrote on 17 jun 2009 in
microsoft.public.inetserver.asp.general:
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.
 
J

jeffctest-google

Evertjan. said:
=================== 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!
 
D

Daniel Crichton

"Evertjan." wrote:
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.
 
E

Evertjan.

Daniel Crichton wrote on 19 jun 2009 in
microsoft.public.inetserver.asp.general:
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"
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,699
Latest member
AnneRosen

Latest Threads

Top