admin管理员组文章数量:1301503
The scenario is as follows:
A multisite install with three sites:
site1
(admin)site2
site3
Q: How to exclude a folder located in the root directory, which should also be associated with site3
?
That is: exclude a particular directory that does not belong to WordPress so that it is accessible from: site3/folderToExclude/
Back in the day site3
was a stand-alone site (now is part of the mentioned MU install), and this rule used to work:
RewriteCond %{REQUEST_URI} !^/(folderToExclude/.*)$
but that's no longer the case.
This is what the file looks like:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_URI} !^/(folderToExclude/.*)$
# add a trailing slash to /wp-admin
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) WordPress_04/$1 [L]
RewriteRule ^(.*\.php)$ WordPress_04/$1 [L]
RewriteRule . index.php [L]
</IfModule>
# END WordPress
The scenario is as follows:
A multisite install with three sites:
site1
(admin)site2
site3
Q: How to exclude a folder located in the root directory, which should also be associated with site3
?
That is: exclude a particular directory that does not belong to WordPress so that it is accessible from: site3/folderToExclude/
Back in the day site3
was a stand-alone site (now is part of the mentioned MU install), and this rule used to work:
RewriteCond %{REQUEST_URI} !^/(folderToExclude/.*)$
but that's no longer the case.
This is what the file looks like:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_URI} !^/(folderToExclude/.*)$
# add a trailing slash to /wp-admin
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) WordPress_04/$1 [L]
RewriteRule ^(.*\.php)$ WordPress_04/$1 [L]
RewriteRule . index.php [L]
</IfModule>
# END WordPress
Share
Improve this question
edited Mar 16, 2021 at 10:46
MrWhite
3,8911 gold badge20 silver badges23 bronze badges
asked Mar 14, 2021 at 7:23
NilsNils
437 bronze badges
2
|
1 Answer
Reset to default 1This "exception" would only be required if you are requesting virtual URLs within /folderToExclude
, as opposed to physical files. Any requests to physical directories and files are naturally excluded by the standard WordPress directives.
RewriteCond %{REQUEST_URI} !^/(folderToExclude/.*)$ # add a trailing slash to /wp-admin RewriteRule ^wp-admin$ wp-admin/ [R=301,L]
This condition (RewriteCond
directive) won't do anything where you've put it. RewriteCond
directives don't do anything by themselves, they apply to the first RewriteRule
directive that follows. In this case, the above rule is checking that the request URL-path matches /wp-admin
and does not start /foldertoExclude/
- the condition is always successful (if A=B then A!=C), so is not doing anything.
However, as written, you couldn't place that condition on the later rule either since the logic is reversed. (Maybe you've used this in the past on a single-site WordPress install?)
Remove that RewriteCond
directive entirely.
Rather than modifying the WordPress code block you should create an additional rule before the # BEGIN WordPress
section, to exclude all requests that start /folderToExclude
from being processed at all by the WordPress directives.
For example:
# Exclude specific directories
RewriteRule ^folderToExclude($|/) - [L]
# BEGIN WordPress
:
No need to repeat the RewriteEngine
directive. No other RewriteCond
directives are necessary.
An alternative is to create another .htaccess
file in the /folderToExclude
directive with a single RewriteEngine Off
(or On
) directive. This will then override the WordPress mod_rewrite directives in the parent .htaccess
file.
本文标签: redirectHow to exclude a directory from WordPress permalinks in a Multisite environment
版权声明:本文标题:redirect - How to exclude a directory from WordPress permalinks in a Multisite environment? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741678004a2391998.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
.htaccess
. So, I'm wondering why you even needed the directive as posted "back in the day"? (That should only have been an optimisation at best.) Please include the contents of your.htaccess
file - maybe there is something else going on? – MrWhite Commented Mar 14, 2021 at 10:51.htaccess
file was a must in order to exclude a folder from a WordPress install. I've updated the post to include the current content of the file. – Nils Commented Mar 16, 2021 at 7:04