WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

Last modified 2 months ago

#19796 closed task (blessed) (fixed)

Multisite installs should work with WordPress in a subdirectory

Reported by: markjaquith Owned by: markjaquith
Milestone: 3.5 Priority: high
Severity: normal Version:
Component: Multisite Keywords: has-patch needs-testing needs-codex
Focuses: Cc:

Description (last modified by ryan)

Currently, Multisite cannot be enabled if WordPress is installed within a subdirectory. This prevents you from using WordPress as an SVN or Git external. We should have parity.

Resolved: find a way to make Multisite work if WordPress is in a subdirectory.

Attachments (23)

19796-hack-day.diff (6.5 KB) - added by markjaquith 4 years ago.
19796-hack-day.2.diff (7.1 KB) - added by evansolomon 4 years ago.
Switch to get_option() and correct the .htaccess install instructions
19796-hack-day.3.diff (8.1 KB) - added by evansolomon 4 years ago.
Add subdirectory base to IIS rewrites
19796-hack-day.4.diff (8.5 KB) - added by markjaquith 4 years ago.
19796-hack-day.5.diff (8.0 KB) - added by markjaquith 4 years ago.
19796-hack-day.6.diff (10.4 KB) - added by johnjamesjacoby 4 years ago.
Includes $base global removal
19796-hack-day.7.diff (10.4 KB) - added by johnjamesjacoby 4 years ago.
Add missing preceding slash to WP_SITEURL_SUBDIR in network.php
19796-hack-day.8.diff (11.0 KB) - added by markjaquith 4 years ago.
19796-hack-day.9.diff (17.7 KB) - added by markjaquith 4 years ago.
19796-hack-day.10.diff (18.1 KB) - added by markjaquith 4 years ago.
19796-hack-day.11.diff (23.3 KB) - added by evansolomon 4 years ago.
19796-hack-day.12.diff (26.8 KB) - added by evansolomon 4 years ago.
Remove unused IIS multisite rewrites from iis7_url_rewrite_rules()
19796-hack-day.13.diff (26.8 KB) - added by duck_ 4 years ago.
19796-hack-day.14.diff (26.8 KB) - added by evansolomon 4 years ago.
19796-hack-day.15.diff (26.9 KB) - added by markjaquith 4 years ago.
Correct path for .htaccess
19796-hack-day.16.diff (26.9 KB) - added by markjaquith 4 years ago.
Also fix path for web.config
19796-hack-day.17.diff (28.3 KB) - added by markjaquith 4 years ago.
19796.diff (26.7 KB) - added by nacin 4 years ago.
Refreshed patch that tries to stick to rewrites to make things work. I think the .htaccess $subdir_match rules are borked, and the technique needs to be tested on Apache 1.3 as well.
19796.2.diff (24.5 KB) - added by markjaquith 4 years ago.
My attempt at merging, which probably failed horribly.
19796.3.diff (23.4 KB) - added by markjaquith 4 years ago.
Refresh, drop the constant.
19796.4.diff (23.5 KB) - added by markjaquith 4 years ago.
Lose the non-capturing regular expression groups.
19796.5.diff (16.2 KB) - added by markjaquith 4 years ago.
Lose the non-capturing regular expression groups.
19796.5.2.diff (16.2 KB) - added by markjaquith 4 years ago.
Lose a lot of cruft. Do the rewrite rule base detection based on ABSPATH, not user-provided URLs.

Download all attachments as: .zip

Change History (110)

#1 @Ipstenu
4 years ago

  • Cc ipstenu@… added

#2 @flashingcursor
4 years ago

  • Cc flashingcursor added

#3 follow-up: @andrea_r
4 years ago

  • Cc andrea@… added

Can you clarify that it's when WordPress is in a folder and the index.php file is moved up a folder?

Because you can enable multisite if the whole install is in a folder, such as for a subdomain. Yes, you can also install it in /whatever/ as long as you're willing to live with that in the address.

You cannot map domains to installs with a foldername in the url though.

#4 @scribu
4 years ago

I could have sworn there was a ticket for this already.

Anyway, glad to see it considered for 3.4.

#5 in reply to: ↑ 3 @PeteMall
4 years ago

Replying to andrea_r:

Can you clarify that it's when WordPress is in a folder and the index.php file is moved up a folder?

Because you can enable multisite if the whole install is in a folder, such as for a subdomain. Yes, you can also install it in /whatever/ as long as you're willing to live with that in the address.

You cannot map domains to installs with a foldername in the url though.

WordPress in a folder ==> site_url != home_url

#6 @kpdesign
4 years ago

  • Cc kparsell-wp@… added

#7 @DrewAPicture
4 years ago

  • Cc xoodrew@… added

#8 @toscho
4 years ago

  • Cc info@… added

#9 @kawauso
4 years ago

  • Cc kawauso added

#10 @markjaquith
4 years ago

  • Description modified (diff)

Taking this out of the description to make it clear that contributions are welcomed from all. We'll call out responsible parties elsewhere.

#11 @DrewAPicture
4 years ago

#12814 seems related

#12 @tfnab
4 years ago

  • Cc martinhh@… added

#13 @westi
4 years ago

  • Cc westi added

#14 @Japh
4 years ago

  • Cc Japh added

#15 @aaroncampbell
4 years ago

  • Cc aaroncampbell added

#16 @johnjamesjacoby
4 years ago

  • Cc johnjamesjacoby added

Note: we use this on BuddyPress.org, Rosetta, and WordCamp.org already.

#17 @masonjames
4 years ago

  • Cc masonjames@… added

#18 @bigdawggi
4 years ago

  • Cc matt@… added

#19 @ryan
4 years ago

  • Description modified (diff)
  • Milestone changed from 3.4 to Future Release

Not happening in 3.4.

#20 @johnbillion
4 years ago

  • Cc johnbillion added

#21 @prettyboymp
4 years ago

  • Cc mpretty@… added

#22 @jkudish
4 years ago

  • Cc joachim.kudish@… added

#23 @tillkruess
4 years ago

  • Cc me@… added

#24 @devesine
4 years ago

  • Cc justin@… added

#25 @NealMcConachie
4 years ago

  • Cc NealMcConachie added

#26 @rfair404
4 years ago

  • Cc rfair404 added

#27 @jblz
4 years ago

  • Cc jblz added

#28 @wonderboymusic
4 years ago

eMusic uses Multisite with WordPress as an external in /wordpress - you can make it work by filtering home/site URLs, you also have to define WP_CONTENT_URL and WP_CONTENT_DIR. Is the issue here that WordPress is supposed to figure this out for you?

#29 @andrea_r
4 years ago

@wonderboymusic the ticket refers to having the WordPress files in a folder off the root, and running the main install as if it were placed in the root. So without the /wordpress/ in the URL.

#30 follow-up: @wonderboymusic
4 years ago

right, we do that, by filtering - so are the tasks for this ticket making that happen automagically?

#31 in reply to: ↑ 30 @scribu
4 years ago

Yes.

#32 @andrea_r
4 years ago

Exactly.

So just to confirm, you run multisite on the public facing side as whatever.com, but it is installed in /wordpress/, and you've moved the root index.php?

This process here:
http://codex.wordpress.org/Giving_WordPress_Its_Own_Directory

#33 @scribu
4 years ago

Sharing your filter-based solution would help to gauge how badly this is needed.

Last edited 4 years ago by scribu (previous) (diff)

#34 @wonderboymusic
4 years ago

  • Keywords has-patch needs-testing added; needs-patch removed

Here are the pieces to making Multisite work in a subdirectory:

1) load files or register external in a subdirectory - let's say "wordpress"
2) move index.php to DOCUMENT_ROOT
3) move wp-config.php to DOCUMENT_ROOT
4) edit .htaccess to internal-redirect ABSPATH files to the proper place

RewriteRule  ^([_0-9a-zA-Z-]+/)?(wp-.*) /wordpress/$2 [L]
RewriteRule  ^([_0-9a-zA-Z-]+/)?(.*\.php)$ /wordpress/$2 [L]

5) Set define( 'WP_CONTENT_DIR' ) if it is different that ABSPATH (if WordPress is in a subdir, it is)
6) Edit index.php to point at /wordpress/wp-blog-header.php instead of ./wp-blog-header.php

items # 1-4 have to happen manually
items # 5-6 can happen automagically in my patch (attaching)

Last edited 4 years ago by wonderboymusic (previous) (diff)

#35 @markjaquith
4 years ago

  • Status changed from new to accepted

Rather thorough attempt that emerged from the WordCamp San Francisco Hack Day. Handles subdir and subdomain multisite installs.

To test, install WP in single site mode in a subdirectory. Move the Site URL ('home') to the root. Set up the Network. Boom.

#36 follow-up: @markjaquith
4 years ago

To do:

  • use get_option( 'home' / 'siteurl' ) instead of home_url() / site_url()
  • Investigate custom content directories
  • IIS

#37 @evansolomon
4 years ago

  • Cc evan@… added

#38 in reply to: ↑ 36 @evansolomon
4 years ago

Replying to markjaquith:

To do:

  • use get_option( 'home' / 'siteurl' ) instead of home_url() / site_url()
  • Investigate custom content directories
  • IIS

Also:

  • Update .htaccess instructions to use the root directory, not ABSPATH

"Add the following to your .htaccess file in /Users/evan/code/wptrunk/wp/"

Should be

"Add the following to your .htaccess file in /Users/evan/code/wptrunk/"

@evansolomon
4 years ago

Switch to get_option() and correct the .htaccess install instructions

#39 @evansolomon
4 years ago

Done in 19796-hack-day.2.diff :

  • use get_option( 'home' / 'siteurl' ) instead of home_url() / site_url()
  • Update .htaccess instructions to use the root directory, not ABSPATH

Already done (just works):

  • Investigate custom content directories

@evansolomon
4 years ago

Add subdirectory base to IIS rewrites

#40 @markjaquith
4 years ago

Cleaned up a variable that was used for two different purposes.

#41 @markjaquith
4 years ago

  • Keywords dev-feedback added

This is looking pretty good to me. Let's have a few more eyes on it.

#42 @scribu
4 years ago

This works for subdirectory installs, for the main blog. For other blogs, I need to figure out the nginx rewrite rules.

@johnjamesjacoby
4 years ago

Includes $base global removal

@johnjamesjacoby
4 years ago

Add missing preceding slash to WP_SITEURL_SUBDIR in network.php

#43 @markjaquith
4 years ago

.10.diff kills the WP subdirectory from wp-admin URLs. So if WordPress is installed in /wp/install/dir/ you don't get URLs like:

http://foo.example.com/wp/install/dir/wp-admin/ OR
http://example.com/foo/wp/install/dir/wp-admin/

Instead, you get:

http://foo.example.com/wp-admin/ OR
http://example.com/foo/wp-admin/

There are a few niggling issues. The login link after multisite creation isn't correct, and it doesn't clear cookies (you have to do it manually in your browser).

#44 @markjaquith
4 years ago

Oh, it also introduces join_with_slashes(). Pass in arguments, either string or array, and you get back a string with no leading or trailing slashes, and exactly one slash between the concatenated members.

Last edited 4 years ago by markjaquith (previous) (diff)

#45 @markjaquith
4 years ago

IIS rules need to be updated.

#46 @evansolomon
4 years ago

.11.diff brings the following magic:

  • Updates IIS rewrites and refactors them into a single HEREDOC to match Apache's
  • Abstracts join_with_slashes() into join_with_string(), which join_with_slashes() then calls

Note: We decided that the login link after multisite creation is fine. It still includes the subdirectory install path, but it works since login.php doesn't need any rewrites. On login, you get properly redirected and receive a new set of cookies.

It would be great to get this tested by someone with an IIS install.

Last edited 4 years ago by evansolomon (previous) (diff)

#47 @evansolomon
4 years ago

Latest patch also skips defining WP_SITEURL_SUBDIR if you're not actually using a subdirectory install. Ridding WordPress of (new) constants, one at a time.

@evansolomon
4 years ago

Remove unused IIS multisite rewrites from iis7_url_rewrite_rules()

#48 @evansolomon
4 years ago

.12.diff removed unused multisite rewrites for IIS from iis7_url_rewrite_rules(). These came over in the original multisite merge (r12697) but were are unused because this function is never called when is_multisite() is true.

This makes iis7_url_rewrite_rules()more closely match mod_rewrite_rules(), which is defined just before it and also doesn't provide multisite rules.

props duck_

Last edited 4 years ago by evansolomon (previous) (diff)

#49 follow-up: @duck_
4 years ago

19796-hack-day.13.diff fixes a small problem in join_with_string() where is_array( $parts ) should be is_array( $part ).

I also noticed that there are a few calls to join_with_slashes() that have a slash as one of the arguments. Isn't this useless? The call to trim() will create an empty string out of it.

#50 in reply to: ↑ 49 @evansolomon
4 years ago

Replying to duck_:

19796-hack-day.13.diff fixes a small problem in join_with_string() where is_array( $parts ) should be is_array( $part ).

I also noticed that there are a few calls to join_with_slashes() that have a slash as one of the arguments. Isn't this useless? The call to trim() will create an empty string out of it.

Thanks. Both of these were remnants of intermediate versions of abstracting these functions that I missed when cleaning them up. The slash arguments to join_with_slashes() are removed in .14.diff.

@markjaquith
4 years ago

Correct path for .htaccess

#51 @markjaquith
4 years ago

.15.diff fixes the path for .htaccess

@markjaquith
4 years ago

Also fix path for web.config

#52 @ancawonka
4 years ago

  • Cc anca-wp@… added

#53 @brianlayman
4 years ago

Note: This includes the $base/$current_site->path fixes from the patch I attached to #18079 last year. #18079 also suggest some changes to the .htaccess code for multi-network compatibility, however if this ticket goes into the next release, #18079 could be closed as it is largely addressed.

This fixes the multinetwork support lost between 2.9 and 3.0 and enables some featues in the wp-multi-network plugin trunk.

#54 @brianlayman
4 years ago

  • Cc Brian@… added

#55 @emzo
4 years ago

  • Cc emzo added

#56 @husobj
4 years ago

  • Cc ben@… added

#57 @iandunn
4 years ago

  • Cc ian_dunn@… added

#58 follow-up: @evansolomon
4 years ago

The latest patch could really use testing from a real IIS install. Unfortunately (at least in this specific case) I have a Mac without any Windows VM, and don't have any other machines with a Windows install. If there's anyone around a Windows install that could setup a local IIS, it would be very helpful in testing this patch.

#59 in reply to: ↑ 58 @jblz
4 years ago

Replying to evansolomon:

The latest patch could really use testing from a real IIS install.

Clean install & db.. Getting an Internal Server Error 500 with 19796-hack-day.16.diff applied. Trunk works as expected.
Win7 x64 - PHP 5.3.16 - FastCGI

EDIT:
Scratch that -- it was just a permissions problem :-/ Continuing to test

Last edited 4 years ago by jblz (previous) (diff)

#60 @developdaly
4 years ago

  • Cc patrick@… added

#61 @nacin
4 years ago

  • Milestone changed from Future Release to 3.5

#62 @markjaquith
4 years ago

Gonna drop this in unless there are any objections.

#63 @markjaquith
4 years ago

Talked with Nacin some. I think we can lose the constant. We only need it when constructing the rewrite rules, and we can do that by leaving home and siteurl from the main site unequal, as is. When generating the rewrite rules, we subtract home from siteurl, slashy slashy, and we have our relative path.

#64 @nacin
4 years ago

In [21813]:

Use network_site_url() for wp-signup.php. props markjaquith. see #19796.

#65 @nacin
4 years ago

  • Keywords needs-refresh added; dev-feedback removed

Needs a pretty major refresh after [21823], see #19235. As I caused it, it's on me unless someone beats me to it.

Additionally, needs refresh from Mark's comment above.

@nacin
4 years ago

Refreshed patch that tries to stick to rewrites to make things work. I think the .htaccess $subdir_match rules are borked, and the technique needs to be tested on Apache 1.3 as well.

@markjaquith
4 years ago

My attempt at merging, which probably failed horribly.

@markjaquith
4 years ago

Refresh, drop the constant.

@markjaquith
4 years ago

Lose the non-capturing regular expression groups.

@markjaquith
4 years ago

Lose the non-capturing regular expression groups.

@markjaquith
4 years ago

Lose a lot of cruft. Do the rewrite rule base detection based on ABSPATH, not user-provided URLs.

#66 @markjaquith
4 years ago

In [22042]:

Make Multisite work when WordPress is installed in a subdirectory. You can now have WordPress Multisite as an SVN external or a Git submodule! props johnjamesjacoby, evansolomon, duck_, jakemgold, nacin, markjaquith. see #19796

#67 @evansolomon
4 years ago

In addition to adding a cool new feature, we actually removed 98 lines of code here. Awesome.

#68 @scribu
4 years ago

  • Keywords needs-refresh removed

Works like a charm.

#69 @mordauk
4 years ago

  • Cc pippin@… added

#70 @markjaquith
4 years ago

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

Open new tickets for distinct issues!

#71 @scribu
4 years ago

Follow-up: #22235

#72 follow-up: @budykiller
4 years ago

Hello.
I've upgrade to WP 3.5 beta 2 to use your patch but i still can't use Multisite installation in a subdirectory while accessing it from the root URL (avoiding the subdirectory in URL).

Is there anything special to do to get it working ?
Here's my post on WP Support forum :
http://wordpress.org/support/topic/accessing-wordpress-subdirectory-from-root-url
Thank you very much for all your work.
Adrien.

#73 in reply to: ↑ 72 @scribu
4 years ago

Replying to budykiller:

I've upgrade to WP 3.5 beta 2 to use your patch but i still can't use Multisite installation in a subdirectory while accessing it from the root URL (avoiding the subdirectory in URL).

Actually, this ticket is about making it work with the subdirectory in the URL.

Anyway, If anyone is interested in getting this working on nginx, here's what I use: https://gist.github.com/4030509

#74 @Ipstenu
4 years ago

No, this is the install in domain.com/folder, run from domain.com

http://core.trac.wordpress.org/ticket/19796#comment:5

You can already install in domain.com/folder and run from domain.com/folder, but without the running in root, when you do that, you can't map domains.

It worked for me.

#75 @scribu
4 years ago

I'm not sure I follow, Ipstenu. In either case, please take a look at #22235

#76 @Ipstenu
4 years ago

We're talking about this: http://codex.wordpress.org/Giving_WordPress_Its_Own_Directory

And it works fine, the user is doing something wrong ;) Addressing in the forums.

#77 follow-up: @toderash
4 years ago

I have installed 3.5-beta3-22639 on nginx with multisite enabled and wordpress core files in a subdirectory: domain.com/wp/wp-*. Works fine except a minor issue in the nav from the admin bar, where links to any of the *network* admin pages omit the /wp/ subdir. Hacking the url to add the /wp/ subdir yields the correct pages, which then function as expected until a form submission, which then attempts to return without the /wp/ subdir. Other nav links in the admin bar to the root site admin correctly include the /wp/ subdir.

Last edited 4 years ago by toderash (previous) (diff)

#78 in reply to: ↑ 77 @nacin
4 years ago

Replying to toderash:

I have installed 3.5-beta3-22639 on nginx with multisite enabled and wordpress core files in a subdirectory: domain.com/wp/wp-*. Works fine except a minor issue in the nav from the admin bar, where links to any of the *network* admin pages omit the /wp/ subdir. Hacking the url to add the /wp/ subdir yields the correct pages, which then function as expected until a form submission, which then attempts to return without the /wp/ subdir. Other nav links in the admin bar to the root site admin correctly include the /wp/ subdir.

That's actually expected behavior. /wp/ doesn't exist anywhere in the database — only rewrite rules. That's what this ticket ended up being about. So you would continue to go to /wp-admin/ and /wp-admin/network. I think the only case where that wouldn't be true is indeed the main/root site, which would keep /wp/ as before. If you removed /wp/ from siteurl for that site, everything should continue to work as the rewrite rules will handle it. If that isn't the behavior you're seeing, please open a ticket.

#79 @nacin
4 years ago

In 23107:

Use $current_site->path instead of $base in wpmu_validate_blog_signup(), as $base is now dead. props MarkJaquith. fixes #22787. see #19796.

#80 follow-up: @sil.linguist
4 years ago

  • Cc sil.linguist added

Does this work with the sub.domain option or just the sub/directory option? It is helpful to know that it is probably user error... so a reply to: http://wordpress.org/support/topic/redirects-for-mutisite-35-beta3 may be more appropriate than here on Trac.

#81 in reply to: ↑ 80 @evansolomon
4 years ago

Replying to sil.linguist:

http://wordpress.org/support/topic/redirects-for-mutisite-35-beta3

The htaccess instructions were fixed in r22982.

#83 @Ipstenu
4 years ago

Updated for WP in it's own directory and where images are.

#84 @Denis-de-Bernardy
2 years ago

Stil some issues, discussed in #23221

Last edited 2 years ago by Denis-de-Bernardy (previous) (diff)

This ticket was mentioned in IRC in #wordpress-dev by nacin. View the logs.


2 years ago

This ticket was mentioned in IRC in #wordpress-dev by nacin. View the logs.


2 years ago

This ticket was mentioned in Slack in #core-multisite by jeremyfelt. View the logs.


2 months ago

Note: See TracTickets for help on using tickets.