0
Your Cart
No products in the cart.

HTMLRemix.com
HTMLRemix.com
by · Published · Updated
Note: This article was published on my web development company blog and re-posted over here for enabling discussion and continuous developments
Now you want to mirror a website of someone else or your own to a new domain. You can simply set it as an addon domain if you have access to original site’s hosting control panel. But what if not? If you use htaccess redirects, it promptly redirects to original site.
Another quick way is to use iframes. Just put following code in your index.html of new domain.
[code] [/code]
But if visitor clicks a link on the page, it wont update the url on the address bar and user fill feel fishy πŸ™‚
Here is the simple script which makes the masking work. It has two portions a php file and one htaccess file.
What php file does is, it opens the original website and grab the content to bump it back to the browser. In the process, it replaces any text with source site url to your new url. So that links on the site and all resource are called from your new domain itself. Smart! isn’t it?
[code]
# index.php
‘;
$host = preg_replace(‘/^[^/]+///’,”,$URL);
$tarray = explode(‘/’,$host);
$host = array_shift($tarray);
$URI = ‘/’ . implode(‘/’,$tarray);
$content = ”;
$fp = @fsockopen($host,80,$errno,$errstr,30);
if(!$fp) { echo “Unable to open socked: $errstr ($errno)n”; exit; }
fwrite($fp,”GET $URI HTTP/1.0rn”);
fwrite($fp,”Host: $hostrn”);
if( isset($_SERVER[“HTTP_USER_AGENT”]) ) { fwrite($fp,’User-Agent: ‘.$_SERVER[“HTTP_USER_AGENT”].”rn”); }
fwrite($fp,”Connection: Closern”);
fwrite($fp,”rn”);
while (!feof($fp)) { $content .= fgets($fp, 128); }
fclose($fp);
if( strpos($content,”rn”) > 0 ) { $eolchar = “rn”; }
else { $eolchar = “n”; }
$eolpos = strpos($content,”$eolchar$eolchar”);
$content = substr($content,($eolpos + strlen(“$eolchar$eolchar”)));
$content = str_replace($wc_source,$wc_mirror,$content);
// replaces paths with / in the begining without full url. not required unless you are in subfolder
$content = str_replace(‘href=”/’,’href=”http://’.$wc_mirror.’/’,$content);
$content = str_replace(‘src=”/’,’src=”http://’.$wc_mirror.’/’,$content);
// $fsize = filesize($fullPath);
$path_parts = pathinfo($fullPath);
$ext = strtolower($path_parts[“extension”]);
// Determine Content Type
switch ($ext) {
case “pdf”: $ctype=”application/pdf”; break;
case “exe”: $ctype=”application/octet-stream”; break;
case “zip”: $ctype=”application/zip”; break;
case “doc”: $ctype=”application/msword”; break;
case “xls”: $ctype=”application/vnd.ms-excel”; break;
case “ppt”: $ctype=”application/vnd.ms-powerpoint”; break;
case “gif”: $ctype=”image/gif”; break;
case “png”: $ctype=”image/png”; break;
case “jpeg”: $ctype=”image/jpg”; break;
case “jpg”: $ctype=”image/jpg”; break;
case “js”: $ctype=”text/javascript”; break;
case “css”: $ctype=”text/css”; break;
}
header(“Pragma: public”); // required
header(“Expires: 0”);
header(“Cache-Control: must-revalidate, post-check=0, pre-check=0”);
header(“Cache-Control: private”,false); // required for certain browsers
header(“Content-Type: $ctype”);
header(“Content-Transfer-Encoding: binary”);
// header(“Content-Length: “.$fsize);
if( preg_match(‘//i’,$content) ) { echo( preg_replace(‘//i’,’‘.$base,$content,1) ); }
else { echo ( str_replace($wc_source,$wc_mirror,preg_replace(‘/<([a-z])([^>]+)>/i’,”<\1\2>“.$base,$content,1) ));
}
?>
[/code]
Now its true that you don’t have any other resource / files on the new domain server. Here comes the htaccess to play its role. htaccess sends all requests to index.php with full path so that index.php can return content for corresponding files from Original website.
[code]
#htaccess file

RewriteEngine On
RewriteBase /
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn’t true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?sql=$1 [L]

[/code]
Implementation is very straight forward. You just need to put in the source and mirror urls in the php file. Everything works out of the box.
Once the files are set with proper urls, when you go to newdomain.com , it will show you content from originalsite.com and all links will word as of newdomain.com/link.html
Tags:
Remiz
Remixed version of unstable human emotions and thirst of mankind actions. UX designer, UI developer and HE of WebCastle Media Pvt LTD

 by · Published December 16, 2008

 by · Published December 2, 2008 · Last modified February 12, 2009

 by · Published February 6, 2009 · Last modified February 12, 2009
If you would like to increase your know-how only keep visiting this website and be updated with the hottest information posted
here.
Hi,
thanks for this script, but not good work for me (not correct show images).
Problem is when image code or not
I commenet (add //) line:
// $content = str_replace(‘src=”/’,’src=”http://’.$wc_mirror.’/’,$content);
Now work all fine.
Steve
Hi Remiz,
Have uploaded your files at our site http://www.craftwholesale.in/ which is redirecting to crafts.itsybitsy.in, but on clicking any link opens only the home page
Please advice
Hi Remiz,
Great Job… kudos from my team….
Thank You..
Is is it possible to tweak the code so subdomains get passed on to the mirror? Ex: foo.mirrordomain.com will load foo.sourcedomain.com (under the mask).
I was actually able to modify this code to get it to work with subdomains! πŸ™‚ Now I have another question… instead of having it load sourcedomain.com, how can I get the mirror domain to load a specific page in sourcedomain such as sourcedomain.com/pagename? I tried making $wc_source = sourcedomain.com/pagename and it doesn’t work.
Ok, my bad for the barrage of emails. I actually figured out how to load a specific page by changing the $URI… Last question! Stylesheets actually are not loading properly… πŸ™ Any fix for this?
How did you get it to work with sub domains?
Ok
All is great but why after i submit data (form use POST method and Header redirect if all is correct with login)
I not get anything and home page reload without any massage or correct redirection to member page?
Thanks
you are genius πŸ˜‰
Hi, Neat post. There’s an issue together with your web site in internet explorer, would test this? IE still is the market chief and a big element of people will leave out your great writing due to this problem.
I have been looking for something like this for a while. I am very happy to hear you have had success with it. I am going to surprise my partner and get myself a pack of this. Hopefully it will work for me like it has for you.
I have dropped your code in, but the images and stylesheets aren’t loading up.
What could the issue be?
Thanks
what about if wc_source is a subfolder like domain.com/example?
Thanx buddy I have wasted lot of time in this code searching you have done a tremandous work. πŸ™‚
Hi Remiz,
It works for a few days but today I got same message as Arash.
Any advise to solve this issue?
Thanks.
Wow.. great article. thanks a lot for sharing
I just did this but why do I get a message Object Moved. This object may be found here (link). I thought it’s supposed to automatically redirect on its own. Did i do something wrong?
plase new and old domain name without “http://”
Hi again,
I do appreciate your help πŸ˜‰
Hi Remiz,
Thanks for your nice tip πŸ™‚
I just tried it, but when I visit my “newdomain.com” it givs me the following error:
Unable to open socked: php_network_getaddresses: getaddrinfo failed: Name or service not known (0)
any idea?
Thanks a lot for your time πŸ™‚
Follow:
Programming
Revolutionizing Web Development with AI: Tools and Techniques for Improved Productivity and Accuracy
21 Dec, 2022
Programming
Apple push notification php example code 2021
15 Jun, 2021
Programming
Solved: MySQL convert_tz returns null on MacOS Catalina using XAMPP
2 Nov, 2019
Google
Why You Should Hire a Creative Marketing Agency for Your Next Campaign
19 Oct, 2019
iPhone
Bring back PPTP VPN on iOS 10 and macOs sierra
1 Oct, 2016
Programming
Curved corner (border-radius) cross browser
24 Sep, 2008
Programming
CSS level 3 styles in Internet Explorer 6 onwards
6 Dec, 2009
Programming
Permanent URL masking for mirroring website using php and htaccess
4 Jan, 2012
SEO
Google sitelinks – How to get for your website
2 Dec, 2008
iPhone
Offline map in iPhone
21 Apr, 2009
Curved corner (border-radius) cross browser
CSS level 3 styles in Internet Explorer 6 onwards
Permanent URL masking for mirroring website using php and htaccess
Google sitelinks – How to get for your website
Β©2016 - Some Rights Reserved
If we die tomorrow we are not going to complaint no more about it. News papers and TV channels may...

source