homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

rewriting domains and maintaining relative html references

 8:19 pm on Jun 30, 2003 (gmt 0)

Ok, here is an interesting question and one wonders whether it's possible to implement this using .htaccess files.

directory structure:


Now, you rewrite www.domainA.com to /toplevel/domainA, however, index.html uses relative URL's like this:

<img src="../graphics/">

My question is this: Can a rewrite be done so that the above rewrite can access the hierarchy above it even though the rewriteengine always rewrites domainA.com to that particular subdirectory?



 6:21 am on Jul 1, 2003 (gmt 0)


Remember that the relative URL is a URL, not a filesystem path. When a relative URL is resolved to a canonical URL, it is the base URL that is used, not a server filepath.

So the answer is that using "../image" in your index file at [domain.com...] is not going to work, because you can't access a resource above your web root URL. But, since you don't need to, it doesn't matter.

I hope this is clear! Just remember that using mod_rewrite, YOU can make the rules of how URLs are mapped to the file system.



 5:12 pm on Jul 1, 2003 (gmt 0)

so essentially, there is no way to use relative urls and make it work?

Here is the problem:

You want a site that can be accessed one of two ways:

A) www.domainA.com
B) www.domainB.com/domainA

Both written to the same subdirectory however in the case of B) you can get away with relative URL's to the path above, with A) seems impossible.

So the solution is: use absolutes?


 4:43 am on Jul 2, 2003 (gmt 0)


You don't have to do anything except use a transparent redirect from domainA/ to domainB/domainA/ and write all your links, relative or absolute, as if you are really in a separate, real domainA/ ... Since the redirect is always applied regardless of whether the link is relative or absolute, you don't have worry about anything. All requests for domainA/<anything> will get redirected to domainB/domainA/<anything>.

Now, if you want to have "shared" hosted images in domainB, which is above domainB/domainA, then what you'll need to do is to refer to those images as if they actually exist in domainA/ and then *not* redirect those requests so that they access files which are actually hosted in the root domainB directory. In order to keep this simple, I'd suggest a separate subdirectory of domainB to be used for these shared images.

As long as you are using transparent (internal) redirects. This ought to work just fine.


Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved