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 = "https://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 https://hasin.wordpress.com and new one at http://blog.ofhas.in
happy weekend!
Wish I had it when I shifted my blog from wordpress to my own hosted server. 😦
Amazing 🙂 You are just great
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.
Excellent!
Heh Heh… i gonna get mine too.. 😉
btw…. many many thanks for savinggggggggggg my timeeee 😀
great use of proxy!
Otherwise that comment woks, less useful. But sure the idea is good to go 😉
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/
great stuff indeed! 😀
sometimes i feel jealous when i see all those uncommon posts are here in your blog 😛
thanks for sharing! 🙂
wow! simply fantastic.
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
Lovely trick.. but Hasin bhai should you not host ur blog fully?
awesome . Thanks for share 😀 .
Simply Marattok!!!
u r a wizard!!!
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?
should work for query string version too 😀
Grest Post!
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…
Wouldn’t you rather mirror the content using wget or use an xml export from wordpress? Also, take duplicate content into account. 😉
@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? 😛
Ek kothai jotil script! 🙂
@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’ve done this in a similar situation:
ProxyPass / https://hasin.wordpress.com/
ProxyPassReverse / https://hasin.wordpress.com/
ProxyPreserveHost on
ProxyVia Off
See other ProxyPassReverse* directives.
Heh heh thats the answer…………………..Thanks a lot
Конкурс для блоггеров от DRUGREVENUE с призовым фондом в 3000 долларов, спешите
nice script))
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?
thanks to vai for sharing this.
Excellent work every buddy can get lots of interesting information, keep on posting this type of brilliant articles.
Brilliant stuff mate, I’ll try it for my wordpress blog.
Thanks