简体   繁体   中英

Apache htaccess redirect only root without change url root

I have a complex situation: myproject.com: is working fine both http and https running Yii2 web application

My client wants to integrate WordPress only for the main page, maintaining the rest of Yii2 web application

I create on the same host a new environment called wp.myproject.com where another user is building WordPress new main page (with other 2/3 static page for example the classic "contact us" or "about us")

What i need is that when visitors go on https://myproject.com it redirect to wp.myproject.com but the url must remain https://myproject.com

I search alot over the net but doesn't find a good solution. Can you help me? Thank's

This can be done, but you need to use mod_proxy . Before you do this, please take note of the security risks that this proposes: https://httpd.apache.org/docs/current/rewrite/flags.html

Also be aware, that mod_proxy needs to be enabled on your server for this to work.

RewriteCond %{HTTP_HOST} ^(www\.)?myproject\.com$ [NC]
RewriteRule ^ http://wp.myproject.com%{REQUEST_URI} [L,NE,P]

This will take either www.myproject.com and myproject.com redirect it to wp.myproject.com/anything but keep the original URL.

You might want to change HTTP to HTTPs, dependent on if you use SSL or not.

Make sure you clear your cache before testing this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM