Categories
Cool Webapps PHP

host your <wordpress.com> 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) http://blog.ofhas.in 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

<?php
$dataurl =$primaryurl = "http://hasin.wordpress.com";//old domain
$secondaryurl = "http://blog.ofhas.in"; //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 http://hasin.wordpress.com and new one at http://blog.ofhas.in

happy weekend!

42 replies on “host your <wordpress.com> blog anywhere, using this 10 lines of proxy script”

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?

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…

@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 🙂

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? 😛

@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 😀

an awesome script. two or three month ago I moved from wordpress.com 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 photomatt.net to ma.tt. (http://ma.tt/2008/01/on-matt/).

and on that script it’s duplicating hasin.wordpress.com’s post and showing all at http://blog.ofhas.in/. Isn’t it?

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,

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?

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 Reply

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