host your <> blog anywhere, using this 10 lines of proxy script

q1. why the hell someone would do that?
a1. if you bought some interesting domain like i do (heh heh) and want your existing blog to be available there as well, without spending hours to move data and to give it same look-n-feel – here’s your time-saving wizard. and beside that, i also dont want to lose my existing blog but i just want to avoid the hassle of re-hosting/migrating 🙂

q2. oh really?? how can I do that?
a2. here you go

$dataurl =$primaryurl = "";//old domain
$secondaryurl = ""; //new domain
$path =array_keys($_GET);
if(!empty($path[0])) $dataurl = "{$primaryurl}/{$path[0]}";
$data = file_get_contents($dataurl);
$pattern = "~{$primaryurl}/([\d\S\/]+)~";
$data = preg_replace($pattern,"{$secondaryurl}/$1",$data);
$data = str_replace(array("<a href=\"{$primaryurl}","<form action=\"{$secondaryurl}"),array("<a href=\"{$secondaryurl}","<form action=\"{$primaryurl}"),$data);
echo $data;

q3. is that all?
a3. nope, you need to modify/write .htaccess file in the root of this new domain

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{QUERY_STRING} (.+)
RewriteRule ^(.*)$ index.php?$1&%{QUERY_STRING}

RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1

this script will also change the urls of all your post and pagination, behaves exactly same as you have hosted your blog in this new url. only drawback is submitting a comment will take you to your original domain, but you can easily fix that but simulating a POST request using curl/stream wrapper/fopen. there is one more vital drawback which is you may lose some IP specific traffic data

have a look at my actual blog and new one at

happy weekend!


  1. kotha ase .. (as you said about the commenting already). wouldn’t these things hurt SEO (duplicate content), etc ?

    I will think of more problems later on :d

  2. Great news for the bloggers. Really useful tips indeed. You ROCK!

    Now I am planning to buy a funky domain name for my own blog. 🙂

    One small question, will it work with every version of SEO friendly url that wordpress supports? or is it for the query string version only?

  3. Other day, i was reading a long ass tutorial on it when i was moving to my own place n domain from wordpress blog….and i would pay $10 to finish the work.

    No need to say, this is very smart script to save time and energy. I’m gonna try this for my new blog and hopefully i don’t have to miss my old bebe! Thanks man…

  4. @till

    wordpress xml export is for one time migration. but if u want to keep both of ur blogs updated, this is the way to do 🙂

    yes, as the 2nd one is a mirror of the first one, there will be duplicate content. but also, you can improve this mirrored blog in manyways, you can add scripts, add external contents which your hosted wordpress blog doesn;t allow or even change the theme just by replacing the theme css 🙂

    it’s something like old wine in a new bottle 🙂

  5. Hasin bhai, want a tip regarding this lets say I wanna see your flickr photos from this site in lightbox. So, I wanna add the <img tag with a parameter after I am reading the data and add rel=’lightbox’
    how do I do it with the pregmatch? 😛

  6. @lenin – wordpress loads jquery automatically. so write a script block at the end of this proxy and use jquery selectors to add that attribute on the fly

    cheese 😀

  7. an awesome script. two or three month ago I moved from and on wp no one have to worry about security – wordpress actually handling all those critical issues. where self hosted blog can be hacked anytime.

    another one point:
    is their any posibilites to get banned from google search engine for duplicate posting? as because matt (founder of wordpress) got banned when he transferred all of his contents (more then 4000 posts) from to (

    and on that script it’s duplicating’s post and showing all at Isn’t it?

  8. i would rather setup an virtual host with reverse proxy and to rewrite old url i would use mod_proxy_html to replace url with in my content.

    an example –
    ProxyHTMLURLMap /old-url /new-url

    this would allow me to change anything without writing a single line of php code.

    even don’t need to place .htaccess as new configuration would take place in site_enabled directory

    thanks for nice content.
    best wishes,

  9. I don’t know, but the script doesn’t work
    I copy paste the whole script, change the url setting, and I found you type ” in different types:
    “ , ” different than ” ?
    I’m sorry, I’m bad at scripting, I don’t know what’s wrong.
    Can u upload the your original script file?

  10. I am not sure because I haven’t yet tried it. But since you haven’t replaced the image tag like anchor and form, will not relative image URLs break?

    Will it work for self hosted wordpress then?

Leave a comment

Your email address will not be published. Required fields are marked *