I have a WordPress page with this structure http://mywebsite.com/page
I want my http://otherdomain.com
to point to http://mywebsite.com/page
but the user should see the http://otherdomain.com
domain at his browser? The A record in my DNS points http://otherdomain.com
and http://mywebsite.com
to the same IP.
How to achieve this goal? I though about VirtualHosts but since the folder /page doesn't really exist in the server but is created dynamically by WordPress via .htaccess
How can I point my domain to the WordPress page?
After Roel answer I edited my htaccess.conf file at the WordPress Bitnami installation to add this:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^otherdomain\.com.br$
RewriteRule (.*) http://www.otherdomain.com.br/$1 [R=301,L]
RewriteRule ^$ http://mywebsite.com.br/page/ [L,R=301]
The code is being called, because it adds the www
to the main URL, but it's not working, because it displays contents from mywebsite.com.br
and not from mywebsite.com.br/page
.
I tried another code which is
RewriteEngine on
RewriteCond %{HTTP_HOST} otherdomain\.com.br [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ http://mywebsite.com.br/page/$1 [L]
In this case, it display the contents from http://mywebsite.com.br/page
however it changes my URL http://mywebsite.com.br/page
as well which is not what I'm looking for, since I want to keep the user's browser at http://otherdomain.com.br
You shouldn't be redirecting the user to mywebsite.com with [L,R=301], rather, you should use the P flag which allows you to ask mod_rewrite to act as a proxy for the domain otherdomain.com. something like this,
make sure to change the css files too to the following,
which will allow all your otherwebsite.com css to become mywebsite.com css and display as otherwebsite.com/css rather than mywebsite.com/page/css
but in order to do this, you need to have mod_proxy loaded and enabled. Do however note that this will reduce performance compared to using mod_proxy directly, as it doesn't handle persistent connections or connection pooling.
You'll need to add rewrite rules.
Try this regex. It may not work, but it will give you some idea on where to find the solution.
Basically you need to use
an external redirect
fromotherdomain
tomywebsite
and thenan internal redirect
frommywebsite
tootherdomain
. But it may cause a loop so you need to use some condition to escape it.All SEO and duplicate content issues aside:
WordPress is aware of the domain it is supposed to be answering to in the database. The WordPress site itself will also redirect based on the domain name set in the WordPress dashboard (under "Settings" => "General").
This isn't going to work well using htaccess. You're actually going to want the domain name
http://otherdomain.com
to point to the server wheremywebsite.com
lives (not using a forward, but modifying the A record in your DNS). The reason is that when you rewrite the domain name, the WordPress site is also going to look for css and js files at that domain (looking for them atotherdomain.com
). If you have the domain pointed to the WordPress server, this will work properly.In order to cause WordPress to allow "answering" to multiple domains, you need to modify the code in your WordPress installation so that it will not rewrite the url to
http://mywebsite.com
. To do this, add the below PHP code to your WordPress theme's function.php file:What you need to do is to add filter(s) to the relevant hooks that return the site URL, so you can modify it as you see fit:
Adding the following filters and functions will cause the desired page to appear as the home page, without the
/page
in the URL: