Jump to content

htaccess redirect wp-json based on cookie


rx3mer

Recommended Posts

Hi all,

I've done something similar with my wp-content folder where I protect the files from being downloaded if you are not logged in and everything works just fine.

With the following code I am trying to say:

  • #if the user doesen't have the cookie "wordpress_login_in"
  • # and the url is wp-json ...
  • # redirect to google
RewriteCond %{HTTP_COOKIE} !.*wordpress_logged_in.*$ [NC]
RewriteCond %{REQUEST_URI} ^.*wp-json/wp/v2/(users|comments|posts|pages|media|types|statuses|taxonomies|categories|tags|settings) [NC]
RewriteRule ^ http://www.google.com [NC,L]

Can anybody tell me why the script doesn't work? I am still seeing the JSON file 

(i have tried redirects from files and folders and everything seems okay. I've also tried creating wp-json folder but then that breaks the api from displaying)

Link to comment
Share on other sites

I've checked the cookies and I've tried cleaning the browser cookies/history a thousand times. I was woundering if it's something to do with the Apache configuration, but htaccess does work and I am able to restrict files and folders. As you know "/wp-json" folder doesen't exist on the server as it's just the API endpoint ?

I will try a different server tomorrow and see how it goes

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.