开发者

CDN : Setting the base URL for images and JS AJAX requests

开发者 https://www.devze.com 2023-02-13 04:33 出处:网络
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\").

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 rewrit开发者_运维技巧e all my ajax request urls absolutely or is there a clever way round this problem?


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消