{"id":521,"date":"2015-11-14T20:54:02","date_gmt":"2015-11-14T19:54:02","guid":{"rendered":"http:\/\/rob006.net\/en\/?p=521"},"modified":"2021-10-22T11:13:55","modified_gmt":"2021-10-22T09:13:55","slug":"wordpress-multisite-a-rewrite-infinite-loop-bug","status":"publish","type":"post","link":"https:\/\/rob006.net\/en\/blog\/wordpress-multisite-a-rewrite-infinite-loop-bug\/","title":{"rendered":"WordPress multisite &#8211; a rewrite infinite loop bug"},"content":{"rendered":"<p>When I created my new home page I used WordPress multisite feature. By the way, I noticed an interesting bug. When I try to view a non-existent image from `wp-content` directory, the server returns an error with code 500 instead of 404. At first I thought it was a problem with hosting, but it turned out to be a bug in the default configuration of `.htaccess` for WordPress running as a multisite with path-based network. <!--more-->It looks like this:<\/p>\n<div class=\"crearfix\"><\/div>\n<pre class=\"lang:apache mark:11-12 decode:true\">RewriteEngine On\r\nRewriteBase \/\r\nRewriteRule ^index\\.php$ - [L]\r\n\r\n# add a trailing slash to \/wp-admin\r\nRewriteRule ^([_0-9a-zA-Z-]+\/)?wp-admin$ $1wp-admin\/ [R=301,L]\r\n\r\nRewriteCond %{REQUEST_FILENAME} -f [OR]\r\nRewriteCond %{REQUEST_FILENAME} -d\r\nRewriteRule ^ - [L]\r\nRewriteRule ^([_0-9a-zA-Z-]+\/)?(wp-(content|admin|includes).*) $2 [L]\r\nRewriteRule ^([_0-9a-zA-Z-]+\/)?(.*\\.php)$ $2 [L]\r\nRewriteRule . index.php [L] \r\n<\/pre>\n<p>The problem exist in two marked lines. They make all the addresses to files like `http:\/\/rob006.net\/en\/wp-content\/file.jpg` treated as `http:\/\/rob006.net\/wp-content\/file.jpg`. The expression `([_0-9a-zA-Z-]+\/)?` is responsible for handling prefixes for sub-directories, but the problem is a `?` at the end. It makes the prefix optional, so if the `http:\/\/rob006.net\/wp-content\/file.jpg` file does not exist, server is trying to internal redirect request to `http:\/\/rob006.net\/wp-content\/file.jpg` (yes, exactly the same address). Since there is no such file, server search rewrite rules again, find the same rule as before and try performs it again. That creates a redirect loop that causes the error 500. Then in the logs you can find these entries:<\/p>\n<pre class=\"wrap:true highlight:0 decode:true\">[Thu Nov 05 23:27:20 2015] [error] [XXX] core.c(3574): [client XXX] 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.\r\n[Thu Nov 05 23:27:20 2015] [error] [XXX] core.c(3574): [client XXX] 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.\r\n<\/pre>\n<p>The solution is to remove `?` sign from these rules.<\/p>\n<h2><b>TL;DR<\/b><\/h2>\n<p>Correct content of `.htaccess` file looks like that:<\/p>\n<pre class=\"lang:apache decode:true\">RewriteEngine On\r\nRewriteBase \/\r\nRewriteRule ^index\\.php$ - [L]\r\n\r\n# add a trailing slash to \/wp-admin\r\nRewriteRule ^([_0-9a-zA-Z-]+\/)?wp-admin$ $1wp-admin\/ [R=301,L]\r\n\r\nRewriteCond %{REQUEST_FILENAME} -f [OR]\r\nRewriteCond %{REQUEST_FILENAME} -d\r\nRewriteRule ^ - [L]\r\nRewriteRule ^([_0-9a-zA-Z-]+\/)(wp-(content|admin|includes).*) $2 [L]\r\nRewriteRule ^([_0-9a-zA-Z-]+\/)(.*\\.php)$ $2 [L]\r\nRewriteRule . index.php [L]<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When I created my new home page I used WordPress multisite feature. By the way, I noticed an interesting bug. When I try to view a non-existent image from `wp-content` directory, the server returns an error with code 500 instead of 404. At first I thought it was a problem with hosting, but it turned [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":524,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[70],"class_list":["post-521","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog","tag-wordpress"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.9 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>WordPress multisite - a rewrite infinite loop bug - Robert Korulczyk \u2013 Homepage<\/title>\n<meta name=\"description\" content=\"When I created my new home page I used Wordpress multisite feature. By the way, I noticed an interesting bug. When I try to view a non-existent image from\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/rob006.net\/en\/blog\/wordpress-multisite-a-rewrite-infinite-loop-bug\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"WordPress multisite - a rewrite infinite loop bug - Robert Korulczyk \u2013 Homepage\" \/>\n<meta property=\"og:description\" content=\"When I created my new home page I used Wordpress multisite feature. By the way, I noticed an interesting bug. When I try to view a non-existent image from\" \/>\n<meta property=\"og:url\" content=\"https:\/\/rob006.net\/en\/blog\/wordpress-multisite-a-rewrite-infinite-loop-bug\/\" \/>\n<meta property=\"og:site_name\" content=\"Robert Korulczyk \u2013 Homepage\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/r.korulczyk\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/r.korulczyk\" \/>\n<meta property=\"article:published_time\" content=\"2015-11-14T19:54:02+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-10-22T09:13:55+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/rob006.net\/en\/wp-content\/uploads\/sites\/2\/2015\/11\/wordpress-logo-notext-rgb.png\" \/>\n\t<meta property=\"og:image:width\" content=\"500\" \/>\n\t<meta property=\"og:image:height\" content=\"500\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Robert Korulczyk\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@rkorulczyk\" \/>\n<meta name=\"twitter:site\" content=\"@rkorulczyk\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Robert Korulczyk\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/rob006.net\/en\/blog\/wordpress-multisite-a-rewrite-infinite-loop-bug\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/rob006.net\/en\/blog\/wordpress-multisite-a-rewrite-infinite-loop-bug\/\"},\"author\":{\"name\":\"Robert Korulczyk\",\"@id\":\"https:\/\/rob006.net\/en\/#\/schema\/person\/6113a3f92b01d11b548ac9718008bded\"},\"headline\":\"WordPress multisite &#8211; a rewrite infinite loop bug\",\"datePublished\":\"2015-11-14T19:54:02+00:00\",\"dateModified\":\"2021-10-22T09:13:55+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/rob006.net\/en\/blog\/wordpress-multisite-a-rewrite-infinite-loop-bug\/\"},\"wordCount\":231,\"commentCount\":3,\"publisher\":{\"@id\":\"https:\/\/rob006.net\/en\/#\/schema\/person\/6113a3f92b01d11b548ac9718008bded\"},\"image\":{\"@id\":\"https:\/\/rob006.net\/en\/blog\/wordpress-multisite-a-rewrite-infinite-loop-bug\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/rob006.net\/en\/wp-content\/uploads\/sites\/2\/2015\/11\/wordpress-logo-notext-rgb.png\",\"keywords\":[\"WordPress\"],\"articleSection\":[\"Blog\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/rob006.net\/en\/blog\/wordpress-multisite-a-rewrite-infinite-loop-bug\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/rob006.net\/en\/blog\/wordpress-multisite-a-rewrite-infinite-loop-bug\/\",\"url\":\"https:\/\/rob006.net\/en\/blog\/wordpress-multisite-a-rewrite-infinite-loop-bug\/\",\"name\":\"WordPress multisite - a rewrite infinite loop bug - Robert Korulczyk \u2013 Homepage\",\"isPartOf\":{\"@id\":\"https:\/\/rob006.net\/en\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/rob006.net\/en\/blog\/wordpress-multisite-a-rewrite-infinite-loop-bug\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/rob006.net\/en\/blog\/wordpress-multisite-a-rewrite-infinite-loop-bug\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/rob006.net\/en\/wp-content\/uploads\/sites\/2\/2015\/11\/wordpress-logo-notext-rgb.png\",\"datePublished\":\"2015-11-14T19:54:02+00:00\",\"dateModified\":\"2021-10-22T09:13:55+00:00\",\"description\":\"When I created my new home page I used Wordpress multisite feature. By the way, I noticed an interesting bug. When I try to view a non-existent image from\",\"breadcrumb\":{\"@id\":\"https:\/\/rob006.net\/en\/blog\/wordpress-multisite-a-rewrite-infinite-loop-bug\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/rob006.net\/en\/blog\/wordpress-multisite-a-rewrite-infinite-loop-bug\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/rob006.net\/en\/blog\/wordpress-multisite-a-rewrite-infinite-loop-bug\/#primaryimage\",\"url\":\"https:\/\/rob006.net\/en\/wp-content\/uploads\/sites\/2\/2015\/11\/wordpress-logo-notext-rgb.png\",\"contentUrl\":\"https:\/\/rob006.net\/en\/wp-content\/uploads\/sites\/2\/2015\/11\/wordpress-logo-notext-rgb.png\",\"width\":500,\"height\":500},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/rob006.net\/en\/blog\/wordpress-multisite-a-rewrite-infinite-loop-bug\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Strona g\u0142\u00f3wna\",\"item\":\"https:\/\/rob006.net\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"WordPress multisite &#8211; a rewrite infinite loop bug\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/rob006.net\/en\/#website\",\"url\":\"https:\/\/rob006.net\/en\/\",\"name\":\"Robert Korulczyk \u2013 Homepage\",\"description\":\"Robert Korulczyk&#039;s blog and homepage\",\"publisher\":{\"@id\":\"https:\/\/rob006.net\/en\/#\/schema\/person\/6113a3f92b01d11b548ac9718008bded\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/rob006.net\/en\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/rob006.net\/en\/#\/schema\/person\/6113a3f92b01d11b548ac9718008bded\",\"name\":\"Robert Korulczyk\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/rob006.net\/en\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/5b6f0a1cac6366571b3681228cdfc493f7e018e4c966f35e75e95f918ae417ff?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/5b6f0a1cac6366571b3681228cdfc493f7e018e4c966f35e75e95f918ae417ff?s=96&d=mm&r=g\",\"caption\":\"Robert Korulczyk\"},\"logo\":{\"@id\":\"https:\/\/rob006.net\/en\/#\/schema\/person\/image\/\"},\"sameAs\":[\"https:\/\/rob006.net\/\",\"https:\/\/www.facebook.com\/r.korulczyk\",\"https:\/\/www.linkedin.com\/in\/robert-korulczyk\/\",\"https:\/\/x.com\/rkorulczyk\",\"https:\/\/www.youtube.com\/channel\/UC8C2t_z08QCYSsmCHQPC2bg\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"WordPress multisite - a rewrite infinite loop bug - Robert Korulczyk \u2013 Homepage","description":"When I created my new home page I used Wordpress multisite feature. By the way, I noticed an interesting bug. When I try to view a non-existent image from","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/rob006.net\/en\/blog\/wordpress-multisite-a-rewrite-infinite-loop-bug\/","og_locale":"en_US","og_type":"article","og_title":"WordPress multisite - a rewrite infinite loop bug - Robert Korulczyk \u2013 Homepage","og_description":"When I created my new home page I used Wordpress multisite feature. By the way, I noticed an interesting bug. When I try to view a non-existent image from","og_url":"https:\/\/rob006.net\/en\/blog\/wordpress-multisite-a-rewrite-infinite-loop-bug\/","og_site_name":"Robert Korulczyk \u2013 Homepage","article_publisher":"https:\/\/www.facebook.com\/r.korulczyk","article_author":"https:\/\/www.facebook.com\/r.korulczyk","article_published_time":"2015-11-14T19:54:02+00:00","article_modified_time":"2021-10-22T09:13:55+00:00","og_image":[{"width":500,"height":500,"url":"https:\/\/rob006.net\/en\/wp-content\/uploads\/sites\/2\/2015\/11\/wordpress-logo-notext-rgb.png","type":"image\/png"}],"author":"Robert Korulczyk","twitter_card":"summary_large_image","twitter_creator":"@rkorulczyk","twitter_site":"@rkorulczyk","twitter_misc":{"Written by":"Robert Korulczyk","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/rob006.net\/en\/blog\/wordpress-multisite-a-rewrite-infinite-loop-bug\/#article","isPartOf":{"@id":"https:\/\/rob006.net\/en\/blog\/wordpress-multisite-a-rewrite-infinite-loop-bug\/"},"author":{"name":"Robert Korulczyk","@id":"https:\/\/rob006.net\/en\/#\/schema\/person\/6113a3f92b01d11b548ac9718008bded"},"headline":"WordPress multisite &#8211; a rewrite infinite loop bug","datePublished":"2015-11-14T19:54:02+00:00","dateModified":"2021-10-22T09:13:55+00:00","mainEntityOfPage":{"@id":"https:\/\/rob006.net\/en\/blog\/wordpress-multisite-a-rewrite-infinite-loop-bug\/"},"wordCount":231,"commentCount":3,"publisher":{"@id":"https:\/\/rob006.net\/en\/#\/schema\/person\/6113a3f92b01d11b548ac9718008bded"},"image":{"@id":"https:\/\/rob006.net\/en\/blog\/wordpress-multisite-a-rewrite-infinite-loop-bug\/#primaryimage"},"thumbnailUrl":"https:\/\/rob006.net\/en\/wp-content\/uploads\/sites\/2\/2015\/11\/wordpress-logo-notext-rgb.png","keywords":["WordPress"],"articleSection":["Blog"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/rob006.net\/en\/blog\/wordpress-multisite-a-rewrite-infinite-loop-bug\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/rob006.net\/en\/blog\/wordpress-multisite-a-rewrite-infinite-loop-bug\/","url":"https:\/\/rob006.net\/en\/blog\/wordpress-multisite-a-rewrite-infinite-loop-bug\/","name":"WordPress multisite - a rewrite infinite loop bug - Robert Korulczyk \u2013 Homepage","isPartOf":{"@id":"https:\/\/rob006.net\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/rob006.net\/en\/blog\/wordpress-multisite-a-rewrite-infinite-loop-bug\/#primaryimage"},"image":{"@id":"https:\/\/rob006.net\/en\/blog\/wordpress-multisite-a-rewrite-infinite-loop-bug\/#primaryimage"},"thumbnailUrl":"https:\/\/rob006.net\/en\/wp-content\/uploads\/sites\/2\/2015\/11\/wordpress-logo-notext-rgb.png","datePublished":"2015-11-14T19:54:02+00:00","dateModified":"2021-10-22T09:13:55+00:00","description":"When I created my new home page I used Wordpress multisite feature. By the way, I noticed an interesting bug. When I try to view a non-existent image from","breadcrumb":{"@id":"https:\/\/rob006.net\/en\/blog\/wordpress-multisite-a-rewrite-infinite-loop-bug\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/rob006.net\/en\/blog\/wordpress-multisite-a-rewrite-infinite-loop-bug\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/rob006.net\/en\/blog\/wordpress-multisite-a-rewrite-infinite-loop-bug\/#primaryimage","url":"https:\/\/rob006.net\/en\/wp-content\/uploads\/sites\/2\/2015\/11\/wordpress-logo-notext-rgb.png","contentUrl":"https:\/\/rob006.net\/en\/wp-content\/uploads\/sites\/2\/2015\/11\/wordpress-logo-notext-rgb.png","width":500,"height":500},{"@type":"BreadcrumbList","@id":"https:\/\/rob006.net\/en\/blog\/wordpress-multisite-a-rewrite-infinite-loop-bug\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Strona g\u0142\u00f3wna","item":"https:\/\/rob006.net\/en\/"},{"@type":"ListItem","position":2,"name":"WordPress multisite &#8211; a rewrite infinite loop bug"}]},{"@type":"WebSite","@id":"https:\/\/rob006.net\/en\/#website","url":"https:\/\/rob006.net\/en\/","name":"Robert Korulczyk \u2013 Homepage","description":"Robert Korulczyk&#039;s blog and homepage","publisher":{"@id":"https:\/\/rob006.net\/en\/#\/schema\/person\/6113a3f92b01d11b548ac9718008bded"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/rob006.net\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/rob006.net\/en\/#\/schema\/person\/6113a3f92b01d11b548ac9718008bded","name":"Robert Korulczyk","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/rob006.net\/en\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/5b6f0a1cac6366571b3681228cdfc493f7e018e4c966f35e75e95f918ae417ff?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/5b6f0a1cac6366571b3681228cdfc493f7e018e4c966f35e75e95f918ae417ff?s=96&d=mm&r=g","caption":"Robert Korulczyk"},"logo":{"@id":"https:\/\/rob006.net\/en\/#\/schema\/person\/image\/"},"sameAs":["https:\/\/rob006.net\/","https:\/\/www.facebook.com\/r.korulczyk","https:\/\/www.linkedin.com\/in\/robert-korulczyk\/","https:\/\/x.com\/rkorulczyk","https:\/\/www.youtube.com\/channel\/UC8C2t_z08QCYSsmCHQPC2bg"]}]}},"_links":{"self":[{"href":"https:\/\/rob006.net\/en\/wp-json\/wp\/v2\/posts\/521","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rob006.net\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rob006.net\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rob006.net\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rob006.net\/en\/wp-json\/wp\/v2\/comments?post=521"}],"version-history":[{"count":11,"href":"https:\/\/rob006.net\/en\/wp-json\/wp\/v2\/posts\/521\/revisions"}],"predecessor-version":[{"id":907,"href":"https:\/\/rob006.net\/en\/wp-json\/wp\/v2\/posts\/521\/revisions\/907"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/rob006.net\/en\/wp-json\/wp\/v2\/media\/524"}],"wp:attachment":[{"href":"https:\/\/rob006.net\/en\/wp-json\/wp\/v2\/media?parent=521"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rob006.net\/en\/wp-json\/wp\/v2\/categories?post=521"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rob006.net\/en\/wp-json\/wp\/v2\/tags?post=521"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}