Make WordPress Core

Opened 14 years ago

Closed 14 years ago

Last modified 14 years ago

#7203 closed defect (bug) (fixed)

Additional linebreak needed when writing to .htaccess

Reported by: johnbillion's profile johnbillion Owned by:
Milestone: 2.6 Priority: high
Severity: major Version: 2.5.1
Component: General Keywords: htaccess has-patch
Focuses: Cc:

Description

When WordPress writes to the .htaccess file when a user first saves their permalink settings, if an .htaccess file already exists and does not end with a blank line, WordPress will corrupt the .htaccess file by appending # BEGIN WORDPRESS onto the end of the last line of the file.

Steps to reproduce:

  1. Either create a new blog or switch off all permalink settings in your current blog.
  2. Create (or edit your existing) .htaccess file so that it contains some data. Do not include a blank line (eg. a line break) at the end of the file.
  3. Now go to your permalink settings page and enable pretty permalinks.
  4. Open up your .htaccess file again and observe that WordPress has appended # BEGIN WORDPRESS to the end of the last line in the file, thus corrupting whatever data the line contains.

Solution: Whack a "\n" in before # BEGIN WORDPRESS to ensure the last line in the file is left alone.

Patch coming up!

Attachments (1)

7203.patch (452 bytes) - added by johnbillion 14 years ago.
Append a "\n" to the rewrite rules marker

Download all attachments as: .zip

Change History (10)

@johnbillion
14 years ago

Append a "\n" to the rewrite rules marker

#1 @johnbillion
14 years ago

  • Keywords has-patch added

#2 @ryan
14 years ago

  • Milestone changed from 2.5.2 to 2.6

#3 @ryan
14 years ago

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

(In [8236]) Make sure htaccess marker begins on a new line. Props johnbillion. fixes #7203

#4 @Viper007Bond
14 years ago

Won't this result in tons of whitespace? If I'm reading it right, every time you update your permalinks it'll add a line break before your WP rules.

#5 @ryan
14 years ago

Hmmm, seems likely.

#6 @johnbillion
14 years ago

Your .htaccess isn't rewritten each time you update your permalinks as rewrite rules are handled internally by WP. It's only rewritten when you disable or enable pretty permalinks.

From testing yesterday it appears that it doesn't result in extraneous whitespace. Not sure why though, as I thought Viper was correct in saying that it would. Might need some more testing.

#7 @ryan
14 years ago

I need to check, but there still might be code that causes rewrites whenever pages are changed, harking back to the days when all rules were in .htaccess.

#8 @DD32
14 years ago

I need to check, but there still might be code that causes rewrites whenever pages are changed, harking back to the days when all rules were in .htaccess.

The rewrite rules are flushed when pages are published still (Going back to when Pages were individual rewrite rules inside WP), not sure about .htaccess :)

#9 @Viper007Bond
14 years ago

Oooh, that's right -- the .htaccess rules don't need to be adjusted, so it makes sense they wouldn't be touched.

Note: See TracTickets for help on using tickets.