#22639 closed defect (bug) (fixed)
Multisite in a subdirectory suggests the wrong location for .htaccess
Reported by: | nacin | Owned by: | nacin |
---|---|---|---|
Milestone: | 3.5 | Priority: | normal |
Severity: | normal | Version: | 3.5 |
Component: | Multisite | Keywords: | has-patch commit dev-reviewed |
Focuses: | Cc: |
Description
Looks like the code suggests ABSPATH, while it should really be $wp_dir_from_root, I imagine?
It's not just the suggestion — note also the file_exists() checks, etc. Basically, any .htaccess reference in wp-admin/network.php.
Reported here: http://wordpress.org/support/topic/multisite-not-working-correctly-when-wp-installed-in-its-own-directory?replies=1
Previously mentioned here: http://core.trac.wordpress.org/ticket/19796#comment:38
Attachments (10)
Change History (22)
#1
follow-up:
↓ 3
@
12 years ago
When not running in a subdir, $wp_dir_from_root can be '/'. Thus, the following code will remove all slashes from ABSPATH:
str_replace( $wp_dir_from_root, '', ABSPATH )
#2
@
12 years ago
Tested with single going to multisite and existing multisite with wp installed in a subdir and in root. Windows and IIS not tested.
#3
in reply to:
↑ 1
@
12 years ago
Replying to ryan:
When not running in a subdir, $wp_dir_from_root can be '/'. Thus, the following code will remove all slashes from ABSPATH:
str_replace( $wp_dir_from_root, '', ABSPATH )
Good catch. Maybe we should be a little more defensive even. In theory, you could install WordPress in a path like /www/wordpress/public_html/wordpress/
, in which case just removing /wordpress
would actually break things. Maybe something like this.
preg_replace( '#' . preg_quote( $wp_dir_from_root ) . '$#', '', ABSPATH )
#4
@
12 years ago
Using preg_replace()
seems like the safest option to me, anything else introduces the potential for multiple paths like evan pointed out causing issues.
A note however, always remember to use the 2nd param to preg_quote
, even if the delimiter has no chance of matching it..
preg_replace( '#' . preg_quote( $wp_dir_from_root, '#' ) . '$#', '', ABSPATH )
#5
@
12 years ago
.4.patch sets $home_path
using preg_replace()
(including Dion's improvement). I think it also fixes a bug from 22639.diff where the files (.htaccess and web.config) were part of the string being trailing slashed. Now $home_path
is trailing slashed.
#6
@
12 years ago
Consider this scenario:
- I have my DOCUMENT_ROOT set to
/Users/nacin/Sites
- I have my WordPress install at
/Users/nacin/Sites/subdir-test/wordpress
. With /, this is ABSPATH. - The "siteurl" is http://localhost/subdir-test/wordpress`
- The "home" URL is http://localhost/subdir-test
In this situation, $wp_dir_from_root is /subdir-test/wordpress/
. And then there's this:
$base = parse_url( $slashed_home, PHP_URL_PATH );
$base is then /subdir-test/. With that, we calculate $wp_siteurl_subdir, which removes $base from the start of $wp_dir_from_root, leaving you with /wordpress/
.
And finally, to calculate $home_path, we shouldn't use ABSPATH minus $wp_dir_from_root, but rather ABSPATH minus $wp_siteurl_subdir. This avoids us from chopping off too much.
With .4.patch, I am told to go to /Users/nacin/Sites
. The proper location is /Users/nacin/Sites/subdir-test
.
Obviously, we've all been away from this code for a few good months, so I figured I would offer this refresher. For sure, some of this should end up in code comments as we set these 7 different variables at the top of network_step2().
#7
@
12 years ago
And after all that, I realize get_home_path() is the function we should have been using from the start.
@
12 years ago
Fairly ambitious attempt to solve this. (Probably needs slash normalisation for Windows. I spell normalisation with an 's' to bribe dd32 to look.)
@
12 years ago
Less ambitious attempt. Unfortunately, this means we're only using get_home_path() for the displayed text, and not for the areas that count - calculating the base for rewrites.
#9
@
12 years ago
- Keywords commit added
.7
is the correct fix. It's written such that it's limited to the issue at hand (which is just a display issue, not a functional issue). I tested it, in multiple WP-in-subdir configurations, and it works.
#10
@
12 years ago
- Keywords has-patch dev-reviewed added
Yeah, we'll go back down the rabbit hole later on.
Also reviewed by dd32.
Also update file_exists() checks