wwfc_barmy_army Posted December 26, 2009 Share Posted December 26, 2009 Hello. Not really sure which section this belongs in but; I have a domain and subdomain, lets say, mydomain.com and mysub.mydomain.com. Mydomain.com has a fully working website, images in a folder called images. I want the same layout on my subdomain, I can link the css and the javascript using the file path, eg ../css/mycss.css, but obviously i can't do the same with the images because of the way the browser gets them and it looks in mysub.mydomain.com. Instead of copying over the images folder, or giving it a full domain path in the image link (eg. <img src="http://mydomain.com/images/myimage.jpg">) is there a way of setting the image paths to default to the main domain directory? Htaccess maybe? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/186369-images-on-subdomain/ Share on other sites More sharing options...
cags Posted December 26, 2009 Share Posted December 26, 2009 Sorry, but what was the reason you can't use "../images/myimage.jpg"? Quote Link to comment https://forums.phpfreaks.com/topic/186369-images-on-subdomain/#findComment-984186 Share on other sites More sharing options...
wwfc_barmy_army Posted December 26, 2009 Author Share Posted December 26, 2009 If i use ../images/image.jpg on the subdomain it looks at mysub.mydomain.com/images/image.jpg, isn't it because of how the browser looks at it? Quote Link to comment https://forums.phpfreaks.com/topic/186369-images-on-subdomain/#findComment-984193 Share on other sites More sharing options...
cags Posted December 26, 2009 Share Posted December 26, 2009 To my knowledge a browser will always parse a URL in the same manner, regardless of whether it is a href attribute, src attribute or link attribute. If the css and javascript files work with this pattern I would have thought the same method would work with an image. Having said this I don't have a sub domain to test it with. I'm guessing it will depend greatly on how the sub domain is implemented. Quote Link to comment https://forums.phpfreaks.com/topic/186369-images-on-subdomain/#findComment-984200 Share on other sites More sharing options...
ignace Posted December 26, 2009 Share Posted December 26, 2009 Why don't you just put all images into images.domain.com? And link to them using: http://images.domain.com/image.jpg Quote Link to comment https://forums.phpfreaks.com/topic/186369-images-on-subdomain/#findComment-984206 Share on other sites More sharing options...
trq Posted December 26, 2009 Share Posted December 26, 2009 You could make aliases to your images, css and javascript within your subdomains vhost configuration if you have access. Alias /css ../css Alias /images ../images Alias /js ../js Quote Link to comment https://forums.phpfreaks.com/topic/186369-images-on-subdomain/#findComment-984208 Share on other sites More sharing options...
haku Posted December 28, 2009 Share Posted December 28, 2009 I personally think that Ignace had a good solution for a couple of reasons. The first is that it solves the problem, though it will involve a little more coding. The second is that because the images are on a separate domain (subdomains are considered separate from the main domain), cookies should not be sent along with the request for the images, meaning that it should increase download speeds for the site a little. And the last is that browsers will only request two items from a single domain at one time, but can request two items from each domain all at the same time. So if your images are coming from a separate domain to the rest of you elements, it should speed up download times as more items can download concurrently. Quote Link to comment https://forums.phpfreaks.com/topic/186369-images-on-subdomain/#findComment-984644 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.