WordPress.org

Make WordPress Core

Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#9246 closed defect (bug) (fixed)

Wordpress cannot update '.htaccess' even though it is writable

Reported by: akd907 Owned by: westi
Milestone: 2.8 Priority: normal
Severity: normal Version: 2.7.1
Component: General Keywords: has-patch tested commit needs-unit-tests
Focuses: Cc:

Description

I have attached a patch which fixes the problem. Here are some details: The culprit function was get_home_path() in file wordpress/wp-admin/includes/file.php. The path to .htaccess was turning out to be:

/u/akshay/public_html/wordpress/wp-admin/options-permalink.php/~akshay/.htaccess

when it actually should be:

/u/akshay/public_html/.htaccess

The reason was that this call was not returning the correct result:

$root = str_replace( $_SERVER["PHP_SELF"], '', $_SERVER["SCRIPT_FILENAME"] );

because $_SERVER["PHP_SELF"] had the value

/~akshay/wordpress/wp-admin/options-permalink.php

and $_SERVER["SCRIPT_FILENAME"] had the value

/u/akshay/public_html/wordpress/wp-admin/options-permalink.php

The main problem was that the path manipulation functions did not consider the presence of /~username. My blog URL is http://web.cecs.pdx.edu/~akshay, which is why the path in PHP_SELF was formed the way it was. I have attached a fix which I hope is generic enough to work. Let me know if it is not (in which case, I would need some hints on how to fix it). The patch is attached.

Attachments (1)

file.diff (904 bytes) - added by akd907 9 years ago.
Patch for a modified version of get_home_path() in file.php

Download all attachments as: .zip

Change History (6)

@akd907
9 years ago

Patch for a modified version of get_home_path() in file.php

#1 @Viper007Bond
9 years ago

  • Keywords needs-testing added

#2 @DD32
9 years ago

  • Keywords has-patch added; htaccess file.php get_home_path removed

#3 @westi
9 years ago

  • Keywords needs-unit-tests added
  • Milestone changed from 2.7.2 to 2.8
  • Owner changed from anonymous to westi
  • Status changed from new to assigned

We need some test cases for the for all different sorts of enviroments especially the less obscure ones that this when the url path does in no way match the on-disk layout.

Then we can ensure we have good coverage in the function of all use cases.

It would be really good to get some tests written. But I would just be really happy to have some test data to mash into some tests.

Not sure this is serious enough to go into the 2.7 branch leaving to 2.8 for now.

#4 @Denis-de-Bernardy
9 years ago

  • Keywords tested commit added; needs-testing removed

patch still works against today's trunk.

confirming the bug. I'm personally getting this, with a similar setup (index.php in ~/denis/, wp-config.php in ~/denis/wp.php):

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /~denis/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /~denis/index.php [L]
</IfModule>

patch allows the files to be written as needed. and it continues to work with both the index.php file and the wp-config.php file in ~/denis/wp/.

haven't tested the following setup, but I'm pretty certain neither of the current and the patch codes will work using it:

  • index.php in ~/denis/test/
  • WP/config.php in ~/denis/wp/

still, the suggested patch is an improvement as compared to the current code base.

#5 @ryan
9 years ago

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

(In [11187]) get_home_path() improvements. Props akd907. fixes #9246

Note: See TracTickets for help on using tickets.