Take the 2-minute tour ×

I am migrating all of my static content to the Amazon S3 CDN. I therefore want to set the base url for images to be the Amazon URL so I can keep the src attribute the same (eg "/imgs/myImage.png").

This works fine for images. Although my JS ajax requests are also sourced in the same way (eg "/ajax/ajaxPage.php") and attempting find my php file on the amazon domain instead of the current domain.

Do I have to rewrite all my ajax request urls absolutely or is there a clever way round this problem?

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

As far as I'm aware, if you use base to change the base of the page, all relative URLs are resolved against it. It would certainly be useful to have a base that was scoped to only certain types of resources, but I'm not aware of one.

So it sounds like you'll need to use absolute URLs for the images, or for all of your in-page links and ajax requests. For the ajax requests, you could readily do a wrapper function in JavaScript that adds the necessary initial part.

share|improve this answer
I am pathing my jaax requests like this now, and seems to be working! url: $baseURL+"/ajax/myfile_ajax.php" –  wilsonpage Feb 25 '11 at 11:38
add comment

You should keep your application as it is. You should add some rewrite rules on your Web server (Apache, nginx and others). something like this for apache

RewriteRule ^/(.*).png$ http://www.somewhere.else/$1.png [R,NC]

RewriteRule ^/ajax/(.*)$ /ajax/$1

share|improve this answer
Only if you want to slow down loading the page for no good reason. With this, every request for an image will first come to his server, then get hit with an unnecessary (and misleading) 302 response ("moved temporarily"), and only then will the browser request the image from the correct location. –  T.J. Crowder Feb 27 '11 at 8:03
R option will make it 301 response by default, but yes it will add an extra load on the server. –  wael34218 Feb 27 '11 at 9:20
add comment

Your Answer


