1

I have a faulty plugin that is generating URLs with /mobile at the end. I am trying to fix the plugin but in the meantime I would like to write a Nginx rewrite rule to redirect as shown below:

http://www.domain.com/article-slug/mobile

to

http://www.domain.com/article-slug/

Can some help me with coming up with the rewrite rule? I researched but could not find something that works in my case. Thanks for your time.

  • What doesn't work, then? – Michael Hampton May 5 '16 at 4:29
  • rewrite ^(.*)mobile$ $1 break; – Pothi Kalimuthu May 5 '16 at 8:25
  • Thanks. How do I write the location block with this redirect? – SmartHomeBeginner May 19 '16 at 12:24
0

Your rewrite won't perform a redirect, but will do something more akin to an internal forward. Assuming you want a 301 sent, then you'd do:

rewrite ^(.*/)mobile$ $1 permanent;
  • Thanks. How do I write the location block with this redirect? – SmartHomeBeginner May 19 '16 at 12:24
  • Well it could just be in the server block. I'm not sure what you'd need for your location block in particular, you could just put it in the "/" location if you want it there – Joshua DeWald May 19 '16 at 16:29

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.