Search code examples
apache.htaccesshttpsapache-config

How to limit access to POST request over HTTPS for a single a file in Apache?


I have limited access to a file service.php located in /var/www/sample to HTTPS with following code:

<Directory /var/www/sample>
        <Files service.php>
                SSLRequireSSL
        </Files>
</Directory>

Now, I would like to limit the access only for POST requests. There is a <Limit> directive that should do this but how should I combine it with the above configuration?


Solution

  • you could use mod_rewrite and add this code:

    RewriteEngine On
    RewriteCond %{REQUEST_URI} ^/service.php # if service.php requested
    RewriteCond %{REQUEST_METHOD} !^POST$ [NC] # and if its not post
    RewriteRule .* - [F] # then block access (403 forbidden)