Reputation: 646
I have a local domain name .dz which doesn't allow DNS changes, I want to redirect the domain and all the pages to another domain .com, and keep the .dz address in the address bar and completely hide the .com domain.
I've searched the whole Internet all solutions doesn't do this, some does the redirect to .com and the .com shows in the address bar and some others redirect only the homepage.
I am wondering if the is a php function to read directly from the .com domain and then writes the content to the .dz domain
I have access to both .htaccess or the PHP files.
Upvotes: 13
Views: 43766
Reputation: 7476
I assume you have access to httpd.conf
or conf
directory,
Try this in your httpd.conf
in the section where mod_proxy is mentioned.
ProxyPass / http://yourwebsite.com/ smax=0 ttl=60 retry=5
ProxyPassReverse / http://yourwebsite.com/ smax=0 ttl=60 retry=5
And may be in case you have to put above rules in separate conf file named httpd-ajp.conf
you will find it in conf/extra
directory.
And when done you have to restart your server before attempting to check.
Edit
As you've said that you don't have access to conf
directory you can try below rule in .htaccess
RewriteEngine On
RewriteRule ^(.*)$ http://example.org/$1 [P]
But you must ensure that mod_proxy is enabled these lines must uncommented in httpd.conf
, hoping you are able to ask it to your hosting provider.
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
Upvotes: 8
Reputation: 6842
There is a method so long as they are hosted separately, however, your .com will need to be live and working.
This is the same as the original Facebook apps system anything that is sent to its URL and then reads and presents the output. whether it's GET, POST or Headers
Basically, it's a PHP scripted proxy that does not change or add anything to the output from the service it's proxying
<?php
$protocol = "http";
$domain = "domain.com";
$ch = curl_init();
$requestPath = $_SERVER['REQUEST_URI'];
$queryString = http_build_query($_GET);
curl_setopt($ch,CURLOPT_URL, $protocol.'://'.$domain.$requestPath);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
$mode = $_SERVER['REQUEST_METHOD'];
$headers = getallheaders();
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
if ($mode == 'POST'){
curl_setopt($ch,CURLOPT_POST, count(http_build_query($_POST)));
curl_setopt($ch,CURLOPT_POSTFIELDS, http_build_query($_POST));
}
$response = curl_exec($ch);
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$header = substr($response, 0, $header_size);
$body = substr($response, $header_size);
$headers = explode("\r\n", $header);
unset($headers[0]);
echo "<pre>";
foreach($headers as $val){
if(strpos($val, "Transfer-Encoding") === false){
header("$val");
flush();
}
}
echo "</pre>";
//close connection
curl_close($ch);
echo $body;
?>
with a rewrite file
RewriteEngine On
RewriteRule .* index.php [L]
if you host this on your .dz domain it will then point to your .com without changing the domain name.
Upvotes: 1
Reputation: 406
@Séddik, Please try like this in your .htaccess file
RewriteCond %{HTTP_HOST} ^www.your-local-domain.dz
RewriteRule ^(.*) http://www.your-another-domain.com/$1 [P]
This may helps you!
Upvotes: 0
Reputation: 329
To show contents from DomainB but show DomainA url there are 2 options:
1. Park domain
If DomainB is your primary domain name, just add DomainA as a Parked Domain.
2. Redirect Using .htaccess file
This method is: Redirect and keep everything after the URL
The first option will show all of the same content on one URL as you would another. To do this, you would modify your .htaccess file for the domain that your users will go to, and insert these lines of code:
RewriteCond %{HTTP_HOST} ^DomainA.com
RewriteRule ^(.*) http://DomainB.com/$1 [P]
If you are using the file manager in cPanel, be sure that you have the option to show hidden files selected.
Upvotes: 0
Reputation: 134
you have mentioned - 'the .dz is too slow and doesn't allow DNS change, that's why i've reserved a .com and I'want to redirect the "slow hosting" .dz to "the fast host ".com'..
When the .dz domain is too slow, it is not worth to invest your time on the redirection of the entire web traffic. It will make things more slower.
You can put a re-direction html (like meta-refresh) in your slow hosting .dz domain and serves the users directly from the .com domain. There is no way you will benefit from keeping the 'slow hosting' .dz domain as your main site...
Upvotes: 0
Reputation: 9
This code shall help you redirect and keep everything after the URL.
RewriteCond %{HTTP_HOST} ^domainname.com
RewriteRule ^(.*) http://domainname.com/$1 [P]
Upvotes: -1
Reputation: 18671
Try with proxy in .htaccess
:
RewriteEngine on
RewriteRule ^ http://domain.com%{REQUEST_URI} [NE,P]
It is possible that this is good enough in your case, if the site is simple.
Upvotes: 5
Reputation: 1305
in fact the web application should be hosted in .dz domain and you should redirect .com permanently to dz. what ever you do except changing DNS in dz domain side it's gonna be a request to .com not itself (the dz domain name).
I mean there is no way unless you want to map all urls and make a curl to .com for each request and change the DOM file and print it. or use Iframe which means you should keep .com domain also.
Upvotes: 2