Forum Moderators: open
This site has no directories; the "URLs" are just strings that are used to make it look like the site has folders and subfolders.
This works fine for URLS that have a single "directory".
www.example.com/one
However, a URL with another level, like:
www.example.com/one/two
will be rewritten to the correct page, except all relative links on the page are broken!
For example, if www.example.com/page.aspx has an image from ~/image.jpg, the URL rewriting from www.example.com/one/two will cause the link to become www.example.com/one/image.jpg and hence the link is broken, as are all other relative links.
I am using HttpContext.Current.RewritePath to rewrite the URLs.
Interestingly enough, this problem does not occur if the URLS are redirected (instead of rewritten) but redirecting defeats the purpose of friendly URLs.
[edited by: Xoc at 4:31 pm (utc) on Feb. 23, 2005]
[edit reason] changed to use example.com [/edit]
[example.com...]
AND
[localhost...]
Is there a way to force relative links to be resolved using the physical file path, as opposed to the URL used in the browser?
Here's a way that actually works.
Use an absolute path like this:
"/whatever.aspx" whenever you link directly to something.
If your dev environment has an extra directory level above the root, then in the global.asax's application start event, either set a static class variable or an application variable based on what's in Request.ServerVariables["SERVER_NAME"]... eg:
if (Context.Request.ServerVariables["SERVER_NAME"] == "localhost")
Application["urlRoot"] = "/subdir";
else
Application["urlRoot"] = "";
and then in your aspx files, use:
"<%=Application["urlRoot"]%>/whatever.aspx" in your links. That way it will work on both your development and production servers.
If it really is a 404, reset the headers so that the user gets a real 404, and if it's a valid category, send the content.
Your question does not belong in this forum, and is totally off-topic. Please use the Link Development [webmasterworld.com] forum for these types of questions.