开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜