rx3mer Posted November 29, 2018 Share Posted November 29, 2018 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) Quote Link to comment https://forums.phpfreaks.com/topic/307960-htaccess-redirect-wp-json-based-on-cookie/ Share on other sites More sharing options...
requinix Posted November 29, 2018 Share Posted November 29, 2018 Don't redirect. Just give a normal 403 error. Better yet, use WordPress's authentication mechanism instead of doing it yourself. Quote Link to comment https://forums.phpfreaks.com/topic/307960-htaccess-redirect-wp-json-based-on-cookie/#findComment-1562526 Share on other sites More sharing options...
rx3mer Posted November 29, 2018 Author Share Posted November 29, 2018 3 hours ago, requinix said: Don't redirect. Just give a normal 403 error. Better yet, use WordPress's authentication mechanism instead of doing it yourself. I will give the 403 error a try. Unfortunatly I need it done using .htaccess I just cant figure out why the redirect wouldnt work Quote Link to comment https://forums.phpfreaks.com/topic/307960-htaccess-redirect-wp-json-based-on-cookie/#findComment-1562534 Share on other sites More sharing options...
requinix Posted November 29, 2018 Share Posted November 29, 2018 It seems fine to me. Are you sure you're not logged in? And more that the cookie does not exist? Try with a fresh incognito/private browser window. Quote Link to comment https://forums.phpfreaks.com/topic/307960-htaccess-redirect-wp-json-based-on-cookie/#findComment-1562535 Share on other sites More sharing options...
rx3mer Posted November 29, 2018 Author Share Posted November 29, 2018 (edited) 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 November 29, 2018 by rx3mer Quote Link to comment https://forums.phpfreaks.com/topic/307960-htaccess-redirect-wp-json-based-on-cookie/#findComment-1562536 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.