Make WordPress Core

Opened 18 years ago

Closed 18 years ago

Last modified 18 years ago

#7203 closed defect (bug) (fixed)

Additional linebreak needed when writing to .htaccess

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

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 18 years ago.
Append a "\n" to the rewrite rules marker

Download all attachments as: .zip

Change History (10)

@johnbillion
18 years ago

Append a "\n" to the rewrite rules marker

#1 @johnbillion
18 years ago

  • Keywords has-patch added

#2 @ryan
18 years ago

  • Milestone 2.5.2 → 2.6

#3 @ryan
18 years ago

  • Resolution → fixed
  • Status new → closed

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

#4 @Viper007Bond
18 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
18 years ago

Hmmm, seems likely.

#6 @johnbillion
18 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
18 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
18 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
18 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.