开发者

URL/Apache redirection question. (domain+directory redirect to sudomain)

开发者 https://www.devze.com 2022-12-11 15:53 出处:网络
I have been trying to figure this out for about 2 hours now. A new requirement came up where it was asked of me to try to find a way to send requests from foo.bar.com/blah to blah.bar.com.

I have been trying to figure this out for about 2 hours now. A new requirement came up where it was asked of me to try to find a way to send requests from foo.bar.com/blah to blah.bar.com.

Technically /blah doesn't exist, but I was hoping to have the ser开发者_运维技巧ver redirect before it gets to that point.

Has anyone had to do this before?

What was the solution?


Try this mod_rewrite rule:

RewriteEngine on
RewriteCond %{HTTP_HOST} =foo.bar.example
RewriteRule ^blah$ http://blah.bar.example

Or for an arbitrary URL path:

RewriteEngine on
RewriteCond %{HTTP_HOST} =foo.bar.example
RewriteRule ^ http://blah.bar.example%{REQUEST_URI}

If you want an untransparent redirect, use a proxy for the request by adding the P flag to your rule. And for a permanent redirect, use R=301.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号