WordPress.org

Make WordPress Core

Opened 7 years ago

Closed 7 years ago

#29945 closed defect (bug) (fixed)

Network setup rules should have a line break at the end

Reported by: SergeyBiryukov Owned by: SergeyBiryukov
Milestone: 4.1 Priority: normal
Severity: normal Version:
Component: Networks and Sites Keywords: good-first-bug has-patch
Focuses: multisite Cc:

Description

The standard WordPress .htaccess rules look like this:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

When creating a network, the suggested rules are:

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]

Before pasting them into .htaccess, I generally remove all existing rules, including the BEGIN/END comments and the <IfModule> tag.

However, if you keep those, it's too easy to make an error:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]</IfModule>

# END WordPress

Note the problematic line at the end:

RewriteRule . index.php [L]</IfModule>

It leads to a 500 Internal Server Error on some installs and to 404 Not Found errors on others.

It should be two separate lines:

RewriteRule . index.php [L]
</IfModule>

We should add a line break to the end of the network setup rules to reduce the chance of this issue.

Attachments (1)

29945.patch (421 bytes) - added by socki03 7 years ago.
Proposed patch for #29945

Download all attachments as: .zip

Change History (5)

#1 @jenmylo
7 years ago

Yep. This broke my multisite install. Thanks for finding the issue, @sergeybiryukov!

This ticket was mentioned in IRC in #wordpress-dev by DrewAPicture. View the logs.


7 years ago

@socki03
7 years ago

Proposed patch for #29945

#3 @johnbillion
7 years ago

  • Keywords has-patch added; needs-patch removed

#4 @SergeyBiryukov
7 years ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 29899:

Add line breaks at the end of network setup rules to avoid unintended merging with a subsequent line.

props socki03.
fixes #29945.

Note: See TracTickets for help on using tickets.