WordPress Multisite, wp-content custom folder and Request exceeded 10 internal redirects limit

I am writing a WordPress plugin that uses the settings API from the class. Thus, the class calls register_settings (), add_settings_field () and add_settings_section () from the class, which works well, except when I try to submit the form, get a server error with the following error in my logs:

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. 

My WordPress installation is a bit weird. It is based on Mark Jaquith WordPress Skeleton repo , and I moved the wp-content folder, my wp-config.php file, outside of WordPress.

I also run WordPress through Vagrant, so this could be a server configuration problem. However, I just tried using my plugin in VVV using a standard WordPress installation and it works great.

My WordPress directory looks like this (composer installs WP in the application directory):

 index.php wp-config.php wp-content/ app/ 

I added my rewrite logs to the trash: http://pastebin.com/QKCFjULZ

My .htaccess file looks like this:

 # 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 
+5
source share
1 answer

You have a redirect loop due to these rules.

 RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-.*) /app/$2 [L] RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ /app/$2 [L] 

Actually, you should keep in mind that your rules are evaluated even after rewriting. Thus, if you have /something/wp-xxx/yyy/zzz , it will be internally rewritten to /app/wp-xxx/yyy/zzz . But now, as you can see, your rule will again match the new uri /app/wp-xxx/yyy/zzz .

Proof looking at your magazines

 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', 

Then you have

 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', 

And it goes on and on ... to the limit of 10 redirects

To avoid this behavior, you need to add some restrictions to your rules to make sure that they will not be evaluated when they do not need it. A simple workaround would be to use a negative lookahead pattern to make sure the current request does not start with /app/ before rewriting it:

 RewriteRule ^((?!app/)[^/]+/)?(wp-.+)$ /app/$2 [L] 

Finally, your htaccess might look like this:

 # 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 

Reminder: 3 rules are executed only for non-existent files / folders.

Examples:

  • http://domain.tld/files/something or http://domain.tld/xxx/files/something will be internally rewritten before /wp-includes/ms-files.php?file=something thanks to rule 1
  • http://domain.tld/wp-something/somethingelse or http://domain.tld/xxx/wp-something/somethingelse (where xxx can be anything but an app ) will be internally rewritten to /app/wp-something/somethingelse thanks to rule 2
  • http://domain.tld/file.php or http://domain.tld/xxx/file.php (where xxx can be anything but an app ) will be internally rewritten to /app/file.php thanks to rule 3
+1
source

Source: https://habr.com/ru/post/1242906/


All Articles