-
Notifications
You must be signed in to change notification settings - Fork 271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add multisite rewrite rules #1083
Conversation
Why does WordPress ship these |
It's required to handle pretty permalinks. Otherwise, WordPress could work without it. Not sure if this is the explanation you were searching for or is there something more complex? |
Aha, thank you! Thinking about this more, I'm not sure. Say we're requesting either these URLs:
Without the rewrite rules, the
|
Looking at the code, this is where it fails to fetch static files. The static file path is |
I spent some time today working on this and have created a regex Now I'm trying to understand whats the best place to do there rewrites. We want rewrites to happen in Playground, not PHP-wasm to avoid adding WP specific code to PHP-wasm. I tested adding a regex rewrite to the request handler and it worked, but static files that aren't part of the filesystem would still break.
|
@adamziel I'm close. The code is all in place and rewrites work, but I can't get it to work consistently. I'm probably not adding rewrite rules in all places or they are not added to WebPHP in all cases. |
Let's look into that on our call later today |
Here is the error I wasn't able to recreate yesterday. Screen.Recording.2024-03-13.at.12.14.05.mov |
404 on static assets looks like the browser tries to fetch() from |
I'm getting closer. There are now tests to confirm rewrites work. There are still some issues with fetching remote assets that I need to resolve. |
Issue for the failing unit test #1112 |
I merged the other PR and rebased this one, let's see if the tests pass. |
packages/playground/remote/src/lib/playground-mu-plugin/0-playground.php
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great, thank you @bgrgicak! My last two asks would be:
- The
0-playground.php
comment I left - Updating the PR title and description to communicate what this PR does now
Thank you for your amazing work! 🎉
*/ | ||
export const wordPressRewriteRules: RewriteRule[] = [ | ||
{ | ||
match: /^\/(.*?)(\/wp-(content|admin|includes).*)/g, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this only match a single path segment? Or not? @bgrgicak
match: /^\/(.*?)(\/wp-(content|admin|includes).*)/g, | |
match: /^\/([^/]+?)(\/wp-(content|admin|includes).*)/g, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, this should work with single and multiple paths. For example /scope:0.1/subsite/
and /subsite/
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 what about greedy vs non-greedy? E.g. how would this be handled /scope:03938/subsite/wp-content/plugins/myplugin/wp-content/image.jpg
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thank you for your patience! :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has been a great learning experience for me. I finally feel comfortable with Regex.
What is this PR doing?
This PR adds support for multisite URL rewrites.
What problem is it solving?
It ensures that all types of WordPress URLs work on Playground.
How is the problem addressed?
By adding support for rewrite rules in PHP WASM and adding a rule to resolve WordPress multisite URLs.
Testing Instructions