rest api - wordpress wp-json prefix issue

I'm using Wordpress 4.9+ which I believe enabled with REST api by default. My permalinks are set to Month and Name

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

But its available in

.php/wp-json/wp/v2/posts

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

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

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/wp-json/wp/v2/posts

But its available in

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

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

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
Share Improve this question edited Jul 11, 2019 at 5:02 Philippe Delteil 1034 bronze badges asked Jun 7, 2018 at 7:10 Faysal AhmedFaysal Ahmed 1311 silver badge4 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 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/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.

You are may trying to get your url like http://example/...../posts instead of http://example/index.php/...../posts

It's the problem of your server. Your server doesn't support that because you're may using Lightpd server.

You can edit rewrite_once in lightpd.conf if it's lightpd server. Also, if your server support htaccess you can add this line to rewrite url.

"^(.+)/?$" => "/index.php/$1"

This is for lightpd and this regex you can use for htaccess.

Update: As you've said your server support htaccess, use this code in your htaccess

Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index.php
RewriteRule ^index.php$ http://example/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745331218a4622885.html

相关推荐

  • rest api - wordpress wp-json prefix issue

    I'm using Wordpress 4.9+ which I believe enabled with REST api by default. My permalinks are set to Month and Name

    5小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信