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!














40 responses so far ↓
Omi Azad // November 29, 2008 at 12:45 am |
Wish I had it when I shifted my blog from wordpress to my own hosted server.
mizan // November 29, 2008 at 12:46 am |
Amazing
You are just great
manchumahara // November 29, 2008 at 12:47 am |
I always tell u about party for new things. Please let me know the party date about the new domain.
BTW, thanks for the tips.
mahmudahsan // November 29, 2008 at 12:48 am |
Excellent!
TRIVUz // November 29, 2008 at 12:50 am |
Heh Heh… i gonna get mine too..
btw…. many many thanks for savinggggggggggg my timeeee
Shahid // November 29, 2008 at 12:53 am |
great use of proxy!
bangaliana // November 29, 2008 at 12:53 am |
Otherwise that comment woks, less useful. But sure the idea is good to go
Md Emran Hasan // November 29, 2008 at 12:54 am |
That’s an amazing piece of code!! So sleek yet so powerful !
Btw, if anybody needs to simulate the POST in case of comments, you can use this wrapper (chooses between cURL and fsockopen – based on availability on server):
http://www.phpfour.com/blog/2008/01/20/php-http-class/
Tahmid Munaz // November 29, 2008 at 12:54 am |
great stuff indeed!
sometimes i feel jealous when i see all those uncommon posts are here in your blog
thanks for sharing!
Arafat Rahman // November 29, 2008 at 12:58 am |
wow! simply fantastic.
host your blog anywhere, using this 10 line proxy script • The HungryCoder // November 29, 2008 at 12:59 am |
[...] For details, visit Hasin Hayder’s Blog [...]
Ehab // November 29, 2008 at 1:00 am |
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
Lenin // November 29, 2008 at 1:03 am |
Lovely trick.. but Hasin bhai should you not host ur blog fully?
ranacse05 // November 29, 2008 at 1:18 am |
awesome . Thanks for share
.
Anis uddin Ahmad // November 29, 2008 at 1:25 am |
Simply Marattok!!!
Nadim Jahangir // November 29, 2008 at 1:28 am |
u r a wizard!!!
ishtiaque // November 29, 2008 at 1:35 am |
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?
hasin // November 29, 2008 at 1:38 am |
should work for query string version too
Lutfar Rahman Nirjhar // November 29, 2008 at 2:02 am |
Grest Post!
junal // November 29, 2008 at 2:22 am |
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 // November 29, 2008 at 4:37 am |
Wouldn’t you rather mirror the content using wget or use an xml export from wordpress? Also, take duplicate content into account.
hasin // November 29, 2008 at 4:41 am |
@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
Lenin // November 29, 2008 at 7:51 am |
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?
host your <wordpress.com> blog anywhere, using this 10 line proxy … | thewordpresssecrets // November 29, 2008 at 8:47 am |
[...] Read more: host your <wordpress.com> blog anywhere, using this 10 line proxy … [...]
shoeb // November 29, 2008 at 1:22 pm |
Ek kothai jotil script!
hasin // November 29, 2008 at 2:21 pm |
@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
Sakib // November 29, 2008 at 8:54 pm |
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?
Nurul // November 30, 2008 at 10:06 am |
Mean Business » Blog Archive » links for 2008-11-30 // November 30, 2008 at 3:00 pm |
[...] host your <wordpress.com> blog anywhere, using this 10 lines of proxy script « The Storytelle… (tags: wordpress sysadmin) [...]
nhm tanveer hossain khan (hasan) // November 30, 2008 at 10:02 pm |
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,
PrettyCoder // December 1, 2008 at 2:54 pm |
I’ve done this in a similar situation:
ProxyPass / http://hasin.wordpress.com/
ProxyPassReverse / http://hasin.wordpress.com/
ProxyPreserveHost on
ProxyVia Off
See other ProxyPassReverse* directives.
Afruj // December 4, 2008 at 12:02 pm |
Heh heh thats the answer…………………..Thanks a lot
Yahoo // December 21, 2008 at 7:27 pm |
Конкурс для блоггеров от DRUGREVENUE с призовым фондом в 3000 долларов, спешите
Vitalyok // January 14, 2009 at 3:24 am |
nice script))
madx // January 31, 2009 at 4:13 am |
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?
maSnun.com » Duplicating WordPress Blog: “The Hasin Vai” Method // March 11, 2009 at 7:29 pm |
[...] duplicate your wordpress blog just using the simple combination of php and mod_rewrite of apache. Read his original blog post here. I am going to explain the mechanism step by step [...]
maSnun // March 11, 2009 at 7:30 pm |
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?
yes!!! i have moved on wordpress still my domain is valid. « hasan’s blog (বল্গ) // April 3, 2009 at 11:12 pm |
[...] a comment » thanks goes to hasin bhai and his this post also with his hosting [...]
tusherdcc // April 8, 2009 at 9:43 am |
thanks to vai for sharing this.
Hosting // October 7, 2009 at 3:42 pm |
Excellent work every buddy can get lots of interesting information, keep on posting this type of brilliant articles.