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 shall start with an example. I want to restrict to POST requests only for http://path/to/logical/abc.xml and restrict to GET only for http://path/to/logical/def.xml. How do I put constraints like this as the paths are logical and location directive is not supported in .htaccess?

The actual problem is to set different authentication constraint on diff logical file. Can you tell me as to how do I put a constraint on logical path in the .htaccess file as location directive is not supported in .htaccess.

share|improve this question
    
What do you mean by "[the] location directive is not supported in .htaccess"? Are you referring to the Location: HTTP request header? –  w3d Oct 15 '13 at 15:18
    
I was refering to the location directive of apache http://httpd.apache.org/docs/current/mod/core.html#location –  user31745 Oct 18 '13 at 5:31

1 Answer 1

I suspect you can probably do this by checking against THE_REQUEST in a RewriteCond (mod_rewrite) directive in .htaccess.

http://example.com/path/to/logical/abc.xml - POST only  
http://example.com/path/to/logical/def.xml - GET ONLY

For our POST only URL, if the request is not a POST request then reject (403 - Forbidden).

RewriteEngine On
RewriteCond ${THE_REQUEST} !^POST [NC]
RewriteRule ^path/to/logical/abc.xml - [F]

For our GET only URL, if the request is not a GET request then reject (403 - Forbidden).

RewriteCond ${THE_REQUEST} !^GET [NC]
RewriteRule ^path/to/logical/def.xml - [F]

(Not tested)

share|improve this answer
    
Bunch of Thanks for the reply. I tried this out and works fine I used regex and could filter only the file without appending the logical path to it . RewriteEngine On RewriteCond ${THE_REQUEST} !^GET [NC] RewriteRule ^(.*)/Filename.xml -[F]. Instead of sending the forbidden I would like to authenticate my abc.xml for basic type of authentication and def for digest type of authentication . How can I do that ?? Can you provide some ideas on that aspect. I am working on Apache 2.2 version –  user31745 Oct 17 '13 at 10:57

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.