rich
rich

Reputation: 1227

.htaccess redirect if request method is post

I have a wordpress site that for various reasons needs a 302 redirect if a certain page is hit with a POST request, any other request should action as usual (ie GET requests). All the methods I have tried however simply perform the redirect regardless of the request method.

RewriteCond %{REQUEST_METHOD} POST
Redirect 302 /gallery /wp-json/posts

Anybody have any ideas?

Upvotes: 2

Views: 2922

Answers (1)

arober11
arober11

Reputation: 2019

You've got the syntax from two entirely different, and competing modules there: mod_rewrite (RewriteCond) and mod_redirect (Redirect), as there's no connection between the two mod_redirect will always redirect, as there's no condition. Similarly you have a condition for a mod_rewrite redirection, but not the actual Redirection directive (RewriteRule). Anyway of the two modules use just use mod_rewrite eg.

RewriteCond %{REQUEST_METHOD} POST
RewriteRule /?gallery /wp-json/posts  [L]

Upvotes: 3

Related Questions