Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect website but keep the original url in the address bar

Tags:

php

.htaccess

dns

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.

like image 268
seddik Avatar asked Dec 24 '16 15:12

seddik


People also ask

How do I permanently redirect a URL?

To redirect a site permanently, one should use a 301 redirect. This type of redirect is best for SEO purposes and also informs the search engines that the site has moved permanently. If you change your domain name and want to point to a different URL, a 301 redirect is your best choice.

Does redirect Change URL?

Using a 301 redirect indicates that the original URL's content has permanently moved to a new URL. Use this type of redirect when you need to forward users and search engines to a new page location and that the original URL won't be coming back.

What is a masking redirect?

A masked redirect empowers you to use content from another domain while keeping your original domain name in the address bar. You use the URL of your homepage (your domain name) as the URL for every page of your website. A masked redirect is also called URL cloaking or domain masking.


2 Answers

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://domain.com/$1 [P]

But you must ensure that mod_proxy is enabled these lines must uncommented in httpd.conf if you able to ask it out with your hosting provider.

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
like image 124
Abhishek Gurjar Avatar answered Oct 11 '22 20:10

Abhishek Gurjar


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.

like image 34
Croises Avatar answered Oct 11 '22 20:10

Croises