非常简单:
我只想公开带有/wp-json前缀的路由,这样我就可以使用headless-WordPress,而不用将我的WordPress站点的其余部分公开给internet。
我正在Apache上运行这个,但还没有找到的正确语法。htaccess。
到目前为止,我已经尝试:
<Directory />
AllowOverride None
</Directory>
<Directory /wp-json*>
AllowOverride All
</Directory>
<Directory /wp-json*/*>
AllowOverride None
</Directory>
以及<Directory "/wp-json/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from all
</Directory>
我的。htaccess位于public_html
根目录。我不确定我是否有。htaccess在错误的目录中,或者如果我使用的语法不起作用。有什么建议吗?EDIT:怀特先生的例子奏效了。我最终added another rewrite rule 对于/wp管理员和我的期末考试.htaccess
如下所示(注意[F]
a的更改[C]
在wp json重写规则上):
RewriteEngine on
# Reject any user requests that are not prefixed "/wp-json"
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule !wp-json($|/) - [C]
RewriteRule !wp-admin($|/) - [F]
# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress