Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I am trying to filter all backend url to one IP in the httpd.conf file using this code:

<Location /admin>
    Order deny,allow
    Deny from all
    Allow from 100.x.xxx.xxx
</Location>

This one works fine. I can't find a way to do the same with /?q=admin.

<Location /?q=admin>
    Order deny,allow
    Deny from all
    Allow from 100.x.xxx.xxx
</Location>

Do I need some regular expression with backslash to escape some of the characters?

share|improve this question
    
Please do not cross-post –  John Conde Sep 19 '13 at 17:27
    
My other post has been put on hold and someone advised me to post on webmasters as it seems not to be related precisely to drupal. –  user2123664 Sep 19 '13 at 17:54
    
Yeah, they asked us if we wanted it moved here (which is the normal procedure) but since you already posted it I declined it. So it would have ended up here way, there's just more cleanup to do by cross-posting. No worries, though. –  John Conde Sep 19 '13 at 17:57
    
Did it work for you now? –  GµårÐïåñ Sep 20 '13 at 8:26
add comment

1 Answer

I would strongly recommend for the second one that has special characters that you use the <LocationMatch> Directive.

The <LocationMatch> directive limits the scope of the enclosed directives by URL, in an identical manner to <Location>. However, it takes a regular expression as an argument instead of a simple string. (http://httpd.apache.org/docs/2.2/mod/core.html#locationmatch)

For your particular case, use:

<LocationMatch /\?q=admin>
    Order deny,allow
    Deny from all
    Allow from 100.x.xxx.xxx
</LocationMatch>
share|improve this answer
    
I didn't succeed with this method but there is an answer here : serverfault.com/questions/540288/… (my question was moved from Drupal to there) –  user2123664 Sep 20 '13 at 13:01
    
Actually the statement "The problem you're having is that <Location> (and <LocationMatch>) directives don't operate on query strings (the thing that comes after the ?)" is inaccurate as <LocationMatch> uses RegEx which means it can take just about anything, as shown clearly in the documentation I linked to. However, if the method provided (which is inelegant to say the least) works for you, then that's all we want, so good luck :) –  GµårÐïåñ Sep 21 '13 at 7:14
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.