How should I allow only GET request to access all the files and script from my server using htaccess?

My web server is Apache

2 Answers 2


You may also want to have a look at the Apache Limit and/or LimitExcept directives. Rewrite rules give you the opportunity to put up a custom error page though.

I believe something like this might work:

<LimitExcept GET HEAD>
  Order Allow,Deny
  Deny from all
  • Already did when I realized I put it in all lower case. :)
    – Rob
    May 18, 2011 at 12:58

How about this?

> RewriteEngine On
> RewriteCond %{REQUEST_METHOD} !=GET
> RewriteRule ^.*$ /path/to
  • This will redirect non-GET requests to another path on the server; it doesn't 'disallow' them. Though you could redirect them to an error page and use the [R=406] on the end of the RewriteRule line.
    – Chris S
    May 18, 2011 at 12:37
  • RewriteCond %{REQUEST_METHOD} !=POST working !
    – Alex
    Apr 26, 2020 at 8:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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