Add trailing slashes in WordPress Multisite without damaging the admin interface or the JSON API

六月ゝ 毕业季﹏ 提交于 2021-01-29 07:27:31

问题


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]

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]

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

and so on...

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


回答1:


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]


来源:https://stackoverflow.com/questions/54536401/add-trailing-slashes-in-wordpress-multisite-without-damaging-the-admin-interface

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!