Uğur Özmen
Uğur Özmen

Reputation: 1

htaccess 301 redirect to disable deleting question/post

I am trying to block deleting posts for the users by using htaccess redirect. When the user clicks on the delete button the following url is https://website.com/?ptype=preview&delete=1&qid=66 (after &delete part =1&qid=66 changes depending on the question(post) id.)

i want to redirect https://website.com/?ptype=preview&delete=*(all posts) to for example https://website.com/ or https://website.com/abc

Can anyone help me about that ?

Upvotes: 0

Views: 36

Answers (1)

Xhynk
Xhynk

Reputation: 13880

Any particular reason you want to use .htaccess rules instead of modifying Capabilities or utilizing the transition_post_status hook, or better yet the before_delete_post hook?

If for some reason you're set on using the .htaccess file, you'll need to check the %{QUERY_STRING} for the delete=1. Something like this should get you started:

RewriteCond %{QUERY_STRING} (^|&)delete=1($|&)
RewriteRule . https://website.com/abc [L,R=301,NC]

Again, I'd argue that using 301s in .htaccess is like using a screwdriver to kill a fly. Does it work? Certainly - though there's probably a better tool for it. Using the before_delete_post hook would provide you with the most extensible, secure, and easy-to-maintain options.

Upvotes: 2

Related Questions