1

I know we can easily redirect a path to another path with Redirect module, but what I want to do is more complicated, my condition is when the user has a specified IP and the route is matched with to a specified path redirect it.

Pseudo code what I'm looking for is

if $path='xxxxx' and $user_ip = 'yyy.yyy.yyy.yyy' redirect to 'zzzzz'

how I can implement this, what I need is where is the best place to implement this?

  • If this is for anonymous traffic then implement a middleware. A good example is BanMiddleware, only that you would return a redirect response instead of a 403 response. – 4k4 Oct 5 '18 at 11:44
1

You can alter the routes (conditionally based on IP) by creating an event subscriber or by using a RouteSubscriber. You should also look at altering existing routes.

  • I've got your point .could you provide more details, please? – Yusef Mohamadi Oct 9 '18 at 4:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.