Jump to content

htaccess redirect wp-json based on cookie


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

Edited by rx3mer
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • 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.