Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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).

http://example.com/the-directory/undefined
http://example.com/the-directory/administrator
http://example.com/the-directory/admin
http://example.com/the-directory/script

How can setup a rewrite so any requests that contains :

/the-directory/{any extra data}

301 redirects to

/the-directory/

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) –  Mayhem Dec 3 '13 at 4:01
add comment

1 Answer

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. –  Mayhem Dec 3 '13 at 10:23
add comment

Your Answer

 
discard

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.