gpt4 book ai didi

wordpress - 语句破坏了 Rewrite* 规则

转载 作者:行者123 更新时间:2023-12-04 15:50:25 26 4
gpt4 key购买 nike

我在 Apache/2.4.34 中使用标准的 wordpress htaccess 规则。如果我添加 <If>声明它刹车重写。

# DEBUG is set to TRUE
<If "-T env('DEBUG')">
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

# 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).*) $1 [L]
RewriteRule ^(.*\.php)$ $1 [L]
RewriteRule . index.php [L]
</If>

/ 之外的所有页面返回:错误请求
您的浏览器发送了此服务器无法理解的请求。
blog.local 172.20.0.1 - - [30/Sep/2018:17:07:58 +0000] "GET /2018/09/19/popular/ HTTP/1.1" 400 226 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36"
[Sun Sep 30 17:07:58.202467 2018] [rewrite:trace3] [pid 7:tid 140686203255528] mod_rewrite.c(482): [client 172.20.0.1:56856] 172.20.0.1 - - [blog.local/sid#55cd2e1aec50][rid#55cd2e246a80/initial] [perdir *If/] add path info postfix: /var/www/html/web/2018 -> /var/www/html/web/2018/09/19/popular/
[Sun Sep 30 17:07:58.202511 2018] [rewrite:trace3] [pid 7:tid 140686203255528] mod_rewrite.c(482): [client 172.20.0.1:56856] 172.20.0.1 - - [blog.local/sid#55cd2e1aec50][rid#55cd2e246a80/initial] [perdir *If/] applying pattern '^index\\.php$' to uri '/var/www/html/web/2018/09/19/popular/'
[Sun Sep 30 17:07:58.202529 2018] [rewrite:trace3] [pid 7:tid 140686203255528] mod_rewrite.c(482): [client 172.20.0.1:56856] 172.20.0.1 - - [blog.local/sid#55cd2e1aec50][rid#55cd2e246a80/initial] [perdir *If/] add path info postfix: /var/www/html/web/2018 -> /var/www/html/web/2018/09/19/popular/
[Sun Sep 30 17:07:58.202543 2018] [rewrite:trace3] [pid 7:tid 140686203255528] mod_rewrite.c(482): [client 172.20.0.1:56856] 172.20.0.1 - - [blog.local/sid#55cd2e1aec50][rid#55cd2e246a80/initial] [perdir *If/] applying pattern '^wp-admin$' to uri '/var/www/html/web/2018/09/19/popular/'
[Sun Sep 30 17:07:58.202557 2018] [rewrite:trace3] [pid 7:tid 140686203255528] mod_rewrite.c(482): [client 172.20.0.1:56856] 172.20.0.1 - - [blog.local/sid#55cd2e1aec50][rid#55cd2e246a80/initial] [perdir *If/] add path info postfix: /var/www/html/web/2018 -> /var/www/html/web/2018/09/19/popular/
[Sun Sep 30 17:07:58.202570 2018] [rewrite:trace3] [pid 7:tid 140686203255528] mod_rewrite.c(482): [client 172.20.0.1:56856] 172.20.0.1 - - [blog.local/sid#55cd2e1aec50][rid#55cd2e246a80/initial] [perdir *If/] applying pattern '^' to uri '/var/www/html/web/2018/09/19/popular/'
[Sun Sep 30 17:07:58.202619 2018] [rewrite:trace4] [pid 7:tid 140686203255528] mod_rewrite.c(482): [client 172.20.0.1:56856] 172.20.0.1 - - [blog.local/sid#55cd2e1aec50][rid#55cd2e246a80/initial] [perdir *If/] RewriteCond: input='/var/www/html/web/2018' pattern='-f' => not-matched
[Sun Sep 30 17:07:58.202638 2018] [rewrite:trace4] [pid 7:tid 140686203255528] mod_rewrite.c(482): [client 172.20.0.1:56856] 172.20.0.1 - - [blog.local/sid#55cd2e1aec50][rid#55cd2e246a80/initial] [perdir *If/] RewriteCond: input='/var/www/html/web/2018' pattern='-d' => not-matched
[Sun Sep 30 17:07:58.202653 2018] [rewrite:trace3] [pid 7:tid 140686203255528] mod_rewrite.c(482): [client 172.20.0.1:56856] 172.20.0.1 - - [blog.local/sid#55cd2e1aec50][rid#55cd2e246a80/initial] [perdir *If/] add path info postfix: /var/www/html/web/2018 -> /var/www/html/web/2018/09/19/popular/
[Sun Sep 30 17:07:58.202666 2018] [rewrite:trace3] [pid 7:tid 140686203255528] mod_rewrite.c(482): [client 172.20.0.1:56856] 172.20.0.1 - - [blog.local/sid#55cd2e1aec50][rid#55cd2e246a80/initial] [perdir *If/] applying pattern '.' to uri '/var/www/html/web/2018/09/19/popular/'
[Sun Sep 30 17:07:58.202681 2018] [rewrite:trace2] [pid 7:tid 140686203255528] mod_rewrite.c(482): [client 172.20.0.1:56856] 172.20.0.1 - - [blog.local/sid#55cd2e1aec50][rid#55cd2e246a80/initial] [perdir *If/] rewrite '/var/www/html/web/2018/09/19/popular/' -> 'index.php'
[Sun Sep 30 17:07:58.202693 2018] [rewrite:trace3] [pid 7:tid 140686203255528] mod_rewrite.c(482): [client 172.20.0.1:56856] 172.20.0.1 - - [blog.local/sid#55cd2e1aec50][rid#55cd2e246a80/initial] [perdir *If/] add per-dir prefix: index.php -> *If/index.php

最后一条消息完全奇怪: add per-dir prefix: index.php -> *If/index.php
怎么了?

最佳答案

我用这些 htaccess 规则遇到了类似的情况:

<If "%{REQUEST_URI} =~ m#^/resources/data/character/[0-9]{1,10}/(avatar|refsheet)\.png$#">
# ... Other stuff here ...
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ resources/generic/default-refsheet.png
</If>

在这种情况下,当最初请求的文件不存在时(并且当它与 resources/generic/default-refsheet.png 中的正则表达式匹配时),请求被重写到相对路径 <If> ,从而导致添加了哑 *If/ 前缀。

Apache 使用的目录前缀 *If/ 似乎是一个取悦者,因为总是先应用 <If> 的内容,然后才能计算实际的目录前缀。

在这种情况下,我发现没有办法让重写的 URL 保持相对,所以我使用了“绝对”(绝对在引号中,因为它实际上仍然相对于虚拟主机的 DocumentRoot,但不相对于 htaccess 所在的位置)。因此将其更改为 /resources/generic/default-refsheet.png (注意首先是 /):
<If "%{REQUEST_URI} =~ m#^/resources/data/character/[0-9]{1,10}/(avatar|refsheet)\.png$#">
# ...
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ /resources/generic/default-refsheet.png
</If>

在这种情况下,重写的 URL 不会以哑 *If/ dir 前缀作为前缀。

因此,对于您的问题,我会尝试在每个重写的规则前面放置一个 / (或一个 /path/to/wordpress/from/document_root/ ):
# DEBUG is set to TRUE
<If "-T env('DEBUG')">
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

# 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).*) /$1 [L]
RewriteRule ^(.*\.php)$ /$1 [L]
RewriteRule . /index.php [L]
</If>

尽管如此,我仍然不能 100% 确定它是否会起作用,也不知道它为什么会起作用(因此我放置了最初的赏金)......

关于wordpress - <If> 语句破坏了 Rewrite* 规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52580249/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com