I’m using WordPress 4.9+ which I believe enabled with REST api by default. My permalinks are set to Month and Name And I’m using Foxhound React theme for my site.

Now my rest api should be available in

http://example.com/wp-json/wp/v2/posts

But its available in

http://example.com/index.php/wp-json/wp/v2/posts

This is why my theme gets 404 error when tries to get data from api.

image error

Now my question is how do I make my REST available without the /index.php prefix

I’ve manually deployed everything in aws ubuntu micro with a Lamp server. WordPress files are in the root folder (/var/www/html/)

Also I have tried mod_rewrite module using the following steps

a2enmod rewrite
sudo service apache2 restart

And this is my .htaccess file

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

2 Answers
2

You need to set the permalink structure of your website.

  1. Goto Settings > Permalink.
  2. Remove index.php from the Custom Structure.
  3. Click on Save Changes.

It re-generate your permalink structure. And you’ll be able to access the posts with http://example.com/index.php/wp-json/wp/v2/posts

Updated:

.htaccess code like below:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /dev.fresh/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /dev.fresh/index.php [L]
</IfModule>

# END WordPress

Note: Change dev.fresh with your own domain.

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *