Ticket #7203 (closed defect: fixed)

Opened 5 months ago

Last modified 5 months ago

Additional linebreak needed when writing to .htaccess

Reported by: johnbillion Assigned to: anonymous
Priority: high Milestone: 2.6
Component: General Version: 2.5.1
Severity: major Keywords: htaccess has-patch
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

7203.patch (452 bytes) - added by johnbillion on 06/29/08 01:46:21.
Append a "\n" to the rewrite rules marker

Change History

06/29/08 01:46:21 changed by johnbillion

  • attachment 7203.patch added.

Append a "\n" to the rewrite rules marker

06/29/08 01:46:37 changed by johnbillion

  • keywords changed from htaccess to htaccess has-patch.

07/02/08 03:17:46 changed by ryan

  • milestone changed from 2.5.2 to 2.6.

07/02/08 03:17:54 changed by ryan

  • status changed from new to closed.
  • resolution set to fixed.

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

07/02/08 22:56:15 changed by Viper007Bond

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.

07/02/08 23:06:11 changed by ryan

Hmmm, seems likely.

07/02/08 23:27:10 changed by johnbillion

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.

07/02/08 23:53:18 changed by ryan

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.

07/03/08 00:23:12 changed by DD32

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 :)

07/03/08 00:55:09 changed by Viper007Bond

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