Search code examples
.htaccess

How to redirect a domain to a subdomain and keep URL using .htaccess?


There used to be a Wordpress running under wp.mydomain.com and a static presentation running under mydomain.com on my webhosting.

Now I want to change the satatic presentation to a Wordpress static page (eg. wp.mydomain.com/static-page) - when user enters mydomain.com, wp.mydomain.com/static-page should display, however the URL shouldn't change.

Currently I use in my .htaccess:

RewriteRule ^$ http://wp.mydomain.com/static-page

however it changes the URL. Is there a way to show static-page and keep the URL mydomain.com using .htacces?


Solution

  • I finally found out the right way to do. There were two problems in my approach - I had to point relatively to the wordpress installation and I also need to change the order of my rewrite rules for subdomains. The correct rewrite rule, which has to be applied as the last one is this:

    RewriteRule ^$ domains/wp.mydomain.com/index.php?page_id={page_id}