1

I would like to have my site visitors go to a specific subdomain based on routeParams

for example if they go to "http://example.com/foo" they will be redirected to "http://foo.example.com"

Can I do that using the routeProvider with something like:

    $routeProvider
        .when('/:my_affiliate', {
            redirectTo: function(routeParams){
                return 'http://' + routeParams.my_affiliate + '.example.com';
            },
      })
        ;

1 Answer 1

7

You can do this with routeProvider how you state. If you want to redirect a user to a different subdomain use window.location with the desired URL. However, consider this will take you of your application. This may however be what you were expecting :D

$routeProvider
    .when('/:my_affiliate', {
        redirectTo: function(routeParams) {
            window.location = 'http://' + routeParams.my_affiliate + '.example.com';
        }
    });

Hope that helps you out!

Sign up to request clarification or add additional context in comments.

2 Comments

That did work. Thanks. But is this the best way to do something like this?
It's not really a common use case to be handled by the client side. However, this approach is a safe bet. Normally any rerouting would be handled server side and taken out of the hands of the client.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.