Peter
Peter

Reputation: 3495

Relative links with subdomains

I've just added a subdomain to my website, but can I point it to files in the main website with relative links? Like in the way that ../ goes back a folder, can you tell it to remove the first part of the url?

Also, I've just seen perhaps it's better putting the image folder as a subdomain too, is it worth doing this?

Upvotes: 3

Views: 3289

Answers (2)

Tim Dawson
Tim Dawson

Reputation: 89

You can't use relative links, but you can use mod_rewrite to help you make a 'pseudo relative' link.

If your desired relative link were: href='folder/filename.typ'
then make it: href='root/folder/filename.typ'
in .htaccess enter: Rewriterule ^root/(.+)$ http://yourdomain.com/$1

You don't have to use 'root' of course, any word will do so long as it's unique in this context (i.e. not an actual folder name).

CAUTION: I found this thread looking for a solution myself. I've only just worked out this method. It does work on my site but I've not tested exhaustively yet.

Upvotes: 0

Wouter van der Neut
Wouter van der Neut

Reputation: 101

It's not possible to link to another domain using relative links, even if it is a subdomain. If you really want to do this you could make some kind of scripting helper to do that, but it would need to run on every page. With this you could run into problems on clients that have scripting disabled.

Putting images in a different subdomain is usually done to optimise loading speed. Browsers usually have a limited number of simultaneous requests to a single (sub)domain. By putting images on a separate (sub)domain you allow the browser to make more simultaneous requests and (in theory) allow your site to be loaded faster.

Upvotes: 5

Related Questions