views:

41

answers:

1

Hello, 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 server redirect before it gets to that point.

Has anyone had to do this before?

What was the solution?

A: 

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.

Gumbo
Thank you for that. Unfortunately this doesn't seem to work. To make sure I am clear: foo.bar.com is a valid subdomain. However /blah is a non-existent directory that I would like to have, when requested, forward/redirect to blah.bar.com. Should the above be working for that?
furstgurshnur
@furstgurshnur: Yes, it should work exactly like that. Where do you want to use that rule? If in the server or virtual host configuration, you need to put a `/` in front of `blah`: `^/blah$`.
Gumbo
Ha! that'll do it. Thanks Gumbo.
furstgurshnur