[Web2.0] How to escape your domain without writing a proxy

Davide Michel 'ZioBudda' Morelli michel a ziobudda.net
Ven 13 Apr 2007 00:36:25 CEST


    Trovato in rete e vi faccio un copia ed incolla.

One of the biggest complaints about AJAX, that I hear, is that it's 
difficult to escape your own domain (actually host, protocol and port) 
It's easy enough to use an XHR object <http://www.w3.org/2006/webapi/> 
to retrieve an XML document (or whatever) from within your own domain 
but a soon as you try to get an RSS 
<http://blogs.law.harvard.edu/tech/rss> feed or access a REST 
<http://en.wikipedia.org/wiki/Representational_State_Transfer> service 
on another box your stuffed.

Well you might not be quite as stuffed as you thought. I hope this helps 
those of you who think .htaccess is only good for redirects and adding 
passwords.

If you use Apache as your web server, and I'm sure you are (although 
other web servers may be just as good or better) you'll hopefully know 
about .htaccess <http://httpd.apache.org/docs/1.3/howto/htaccess.html> 
files. If you don't they are plain text files that tell apache to do 
stuff before returning the page.

There is a little feature of Apache called mod_rewrite. It's a 
rule-based rewriting engine to rewrite requested URLs on the fly. It can 
be used to make your URLs pretty but here it's going to act as our proxy.

First create a file called .htaccess with the following code.

RewriteEngine on
RewriteRule ^/call/(.*)$ http://backstage.bbc.co.uk/$1 [P]

Then all you need to do is on your server create a folder called "bbc" 
or whatever. Upload this file to it and that folder will act as a proxy 
server to your AJAX application. Nice, Job done and only two lines of code.

-- 
Michel 'ZioBudda' Morelli                       michel a ziobudda.net
Consulenza sistemistica in ambito OpenSource.
Sviluppo applicazioni web dinamiche (LAMP+Ajax)
Telefono: +39-3939890025 --  Fax: +39-0291390660

http://www.ziobudda.net                         ICQ: 58351764  
http://www.ziobuddalabs.it                      Skype: zio_budda
http://www.ajaxblog.it        			MSN: michel a ziobuddalabs.it                   

-------------- parte successiva --------------
Un allegato HTML è stato rimosso...
URL: http://lists.ziobudda.net/pipermail/web2.0/attachments/20070413/311f3f20/attachment.html


Maggiori informazioni sulla lista Web2.0