I'm having a small issue - my error log is filling up with requests to a directory folder on my site (but with added data that shouldn't be there).


How can setup a rewrite so any requests that contains :

/the-directory/{any extra data}

301 redirects to


What I have tried is :

rewrite ^/the-directory/(.*)$ /the-directory/ last;

But that just gets stuck in a redirect loop. Any help would be greatly appreciated.

  • If these are not legitimate requests, you should probably just continue sending the 404 error. – Michael Hampton Dec 3 '13 at 3:57
  • those are just some examples - some are legit requests (which appears to be a typo in the link to my site) – Brian Smith Dec 3 '13 at 4:01

Try this one:

rewrite ^/the-directory/.+$ /the-directory/ permanent;

You stuck in a redirect loop because regex ^/the-directory/(.*)$ matches /the-directory/.

| improve this answer | |

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.