在WordPress多站点中添加尾部斜杠而不会损坏管理界面或JSON API [英] Add trailing slashes in WordPress Multisite without damaging the admin interface or the JSON API

查看:165
本文介绍了在WordPress多站点中添加尾部斜杠而不会损坏管理界面或JSON API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于WordPress多站点安装,我的.htaccess文件包含以下部分:

For a WordPress multisite installation I am having the following part of my .htaccess:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^.]+)([^./])$ %{REQUEST_URI}/ [L,R=301,NE]

在单个WordPress安装中,/wp-admin和/wp-json始终紧随域之后,我可以使用以下命令将它们从尾部斜杠规则中排除:

In a single WordPress installation where /wp-admin and /wp-json always follow directly after the domain I can exclude those from the trailing slash rule with this:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/wp-admin
RewriteCond %{REQUEST_URI} !^/wp-json
RewriteRule ^ / [R=301,L]

在WordPress多站点中,可以通过以下方式访问管理界面和JSON API:

In a WordPress multisite the Admin interface and the JSON API can be reached like this:

www.example.com/wp-admin
www.example.com/wp-admin/whatever
www.example.com/site1/wp-admin
www.example.com/site2/wp-admin/whatever?whatever

www.example.com/wp-json
www.example.com/wp-json/whatever
www.example.com/site1/wp-json
www.example.com/site2/wp-json/plugin-7/12/request

以此类推...

将它们放在一起的正确的.htaccess规则是什么?尝试某些事情没有成功.不一定是WordPress特有的问题.

What is the correct .htaccess rule for putting this together? Have tried certain things without success. Not necessarily a WordPress specific question.

推荐答案

没关系,我终于想通了:

Nevermind I have finally figured it out:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/wp-json
RewriteCond %{REQUEST_URI} !^/wp-admin
RewriteCond %{REQUEST_URI} !^/([_0-9a-zA-Z-]+)/wp-json
RewriteCond %{REQUEST_URI} !^/([_0-9a-zA-Z-]+)/wp-admin
RewriteRule ^([^.]+)([^./])$ %{REQUEST_URI}/ [L,R=301,NE]

这篇关于在WordPress多站点中添加尾部斜杠而不会损坏管理界面或JSON API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆