rug*_*ert 5 apache wordpress .htaccess redirect
我正在编写一个WordPress插件,它使用类中的设置API.所以该类从类中调用register_settings(),add_settings_field()和add_settings_section(),除非我尝试提交表单时获取服务器错误,并在我的日志中出现以下错误:
AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
Run Code Online (Sandbox Code Playgroud)
我的WordPress安装有点奇怪.它基于Mark Jaquith的WordPress Skeleton repo,我已经移动了我的wp-content文件夹,我的wp-config.php文件在WordPress之外.
我也通过Vagrant运行WordPress,因此它可能是服务器配置问题.但是,我只是尝试使用标准的WordPress安装在VVV中使用我的插件,并且它的工作正常.
我的WordPress目录看起来像这样(作曲家将WP安装到app dir):
index.php
wp-config.php
wp-content/
app/
Run Code Online (Sandbox Code Playgroud)
我已将重写日志添加到粘贴箱中:http://pastebin.com/QKCFjULZ
我的.htaccess文件如下所示:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule . - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-.*) /app/$2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ /app/$2 [L]
RewriteRule . /index.php [L]
Options -indexes
</IfModule>
# END WordPress
Run Code Online (Sandbox Code Playgroud)
由于这些规则,您有一个重定向循环
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-.*) /app/$2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ /app/$2 [L]
Run Code Online (Sandbox Code Playgroud)
实际上,您必须记住,即使在重写之后,您的规则也会被评估。因此,如果有的话,/something/wp-xxx/yyy/zzz它将在内部重写为/app/wp-xxx/yyy/zzz. 但现在,正如您所看到的,您的规则将再次与新的 uri 匹配/app/wp-xxx/yyy/zzz。
证明,查看你的日志
applying pattern '^([_0-9a-zA-Z-]+/)?(wp-.*)' to uri 'wp-admin/network/options.php',
rewrite 'wp-admin/network/options.php' -> '/app/wp-admin/network/options.php',
Run Code Online (Sandbox Code Playgroud)
那么你就有了
applying pattern '^([_0-9a-zA-Z-]+/)?(wp-.*)' to uri 'app/wp-admin/network/options.php',
rewrite 'app/wp-admin/network/options.php' -> '/app/wp-admin/network/options.php',
Run Code Online (Sandbox Code Playgroud)
就这样一直持续下去……直到达到 10 次重定向的限制
为了避免这种行为,您需要对规则添加一些限制,以确保它们在不必要时不会被评估。一个简单的解决方法是使用负先行模式来确保当前请求在重写之前不是以以下方式开头:/app/
RewriteRule ^((?!app/)[^/]+/)?(wp-.+)$ /app/$2 [L]
Run Code Online (Sandbox Code Playgroud)
最后,你的 htaccess 可能看起来像这样
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
# Rule 1
RewriteRule ^([^/]+/)?files/(.+)$ wp-includes/ms-files.php?file=$2 [L]
# Rule 2
RewriteRule ^((?!app/)[^/]+/)?(wp-.+)$ /app/$2 [L,QSA]
# Rule 3
RewriteRule ^((?!app/)[^/]+/)?(.+\.php)$ /app/$2 [L,QSA]
RewriteRule ^ index.php [L]
Options -Indexes
</IfModule>
# END WordPress
Run Code Online (Sandbox Code Playgroud)
提醒:这 3 条规则仅对不存在的文件/文件夹执行。
例子:
http://domain.tld/files/something或者
http://domain.tld/xxx/files/something将/wp-includes/ms-files.php?file=something根据规则 1进行内部重写http://domain.tld/wp-something/somethingelseor http://domain.tld/xxx/wp-something/somethingelse(其中xxx可以是除 之外的任何内容)将根据规则 2app进行内部重写/app/wp-something/somethingelsehttp://domain.tld/file.phpor http://domain.tld/xxx/file.php(其中xxx可以是除 之外的任何内容)将根据规则 3app进行内部重写/app/file.php| 归档时间: |
|
| 查看次数: |
562 次 |
| 最近记录: |