Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
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
up vote 2 down vote accepted

Try this one:

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

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

share|improve this answer
Thank you, I knew I wasn't too far off. – Brian Smith Dec 3 '13 at 10:23

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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