使用 REST API V2 的 wordpress 中 http:///localhost/wp-json/wp/v2/posts 上的 404
404 on http://localhost/wp-json/wp/v2/posts in wordpress using REST API V2
我在 http://localhost/wp-json/wp/v2/posts 路线上收到 404。我将永久链接类型更改为普通。仍然遇到同样的问题。
如果它有用,我是 ubuntu 16.04 桌面最近从 15.10 升级,php5.6 升级到 7.0 时遇到问题。现在 php 7.0
编辑1:
尝试了所有其他永久链接设置组合,没有结果!
您需要授予对您的 wp-content 文件夹的权限。要更改权限,请在终端中使用以下命令。
sudo chmod -R 755 wp-content/
更改权限后还是显示404错误然后允许apache的AllowOverride,步骤如下:
导航到 /etc/apache2/sites-enabled
并打开 000-default
所有 AllowOverride
变量都设置为 None,我将其替换为 All
。
此更改后使用以下命令启用 mod:
a2enmod rewrite
并重启apache服务如下命令:
sudo service apache2 restart
在根 link 之后添加 index.php
:
http://localhost/wordpress/index.php/wp-json/wp/v2/posts
这对我有用。
http://localhost/?rest_route=/wp/v2/posts
应该有效。
详情请参阅 https://developer.wordpress.org/rest-api/using-the-rest-api/discovery/。
首先,您需要使用以下命令启用 apache 重写模块:
sudo a2enmod rewrite
然后我们必须编辑虚拟主机的配置文件
sudo nano /etc/apache2/sites-available/your_config.conf
并添加以下指令
<Directory /var/www/your_root_directory>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
注意:更改目录路径
现在我们的文件应该是这样的
<VirtualHost *:80>
<Directory /var/www/your_root_directory>
. . .
</Directory>
ServerName midomain.com
. . .
</VirtualHost>
现在重启apache服务
sudo service apache2 restart
在网站的根目录中创建一个 .htacces 文件
sudo nano /var/www/your_root_directory/.htaccess
最后加入.htaccess
RewriteEngine on
RewriteRule ^wp-json/wp/v2/posts$ ?rest_route=/wp/v2/posts [NC]
我在 http://localhost/wp-json/wp/v2/posts 路线上收到 404。我将永久链接类型更改为普通。仍然遇到同样的问题。
如果它有用,我是 ubuntu 16.04 桌面最近从 15.10 升级,php5.6 升级到 7.0 时遇到问题。现在 php 7.0
编辑1: 尝试了所有其他永久链接设置组合,没有结果!
您需要授予对您的 wp-content 文件夹的权限。要更改权限,请在终端中使用以下命令。
sudo chmod -R 755 wp-content/
更改权限后还是显示404错误然后允许apache的AllowOverride,步骤如下:
导航到 /etc/apache2/sites-enabled
并打开 000-default
所有 AllowOverride
变量都设置为 None,我将其替换为 All
。
此更改后使用以下命令启用 mod:
a2enmod rewrite
并重启apache服务如下命令:
sudo service apache2 restart
在根 link 之后添加 index.php
:
http://localhost/wordpress/index.php/wp-json/wp/v2/posts
这对我有用。
http://localhost/?rest_route=/wp/v2/posts
应该有效。
详情请参阅 https://developer.wordpress.org/rest-api/using-the-rest-api/discovery/。
首先,您需要使用以下命令启用 apache 重写模块:
sudo a2enmod rewrite
然后我们必须编辑虚拟主机的配置文件
sudo nano /etc/apache2/sites-available/your_config.conf
并添加以下指令
<Directory /var/www/your_root_directory>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
注意:更改目录路径
现在我们的文件应该是这样的
<VirtualHost *:80>
<Directory /var/www/your_root_directory>
. . .
</Directory>
ServerName midomain.com
. . .
</VirtualHost>
现在重启apache服务
sudo service apache2 restart
在网站的根目录中创建一个 .htacces 文件
sudo nano /var/www/your_root_directory/.htaccess
最后加入.htaccess
RewriteEngine on
RewriteRule ^wp-json/wp/v2/posts$ ?rest_route=/wp/v2/posts [NC]