-
-
Notifications
You must be signed in to change notification settings - Fork 18
How to bypass the URL rewriting? #69
Comments
The biggest problem is that replaceDomain/replaceDomainUsingLessMemory are very intrusive. They replace URLs regardless of where they are (anchors, images, JS, comments, pure text, legitimate links to another domain from the pool). Got some suggestions with progressive complexity. I guess the simplest workaround would be to add filter hook in fixContentUrls i.e.
This way everyone can apply their own filters after your plugin did the job. Another way would be to allow special keyword in URL (i.e. httpmd:// as a protocol or urls starting with [FORCE]) which you then replace/remove in your filter. Disadvantage of this is that people will endup with bunch of broken URLs if they disable the plugin. Similarly you can add a shortcode that folks can use to add URL which your plugin will treat differently. Same disadvantage as above. The heaviest duty approach would be to search content for the actual tags with HTML href or src attributes (a, img, link) and replace the URLs unless tags contain a speciffic attribute i.e. data-nomd. Hope that this gives you some ideas. |
@QuietNoise thanks for your suggestions. I'll put some thought on it to see what option fits better. |
Hello folks! I just needed this functionality now and what I thought of is changing fixContentUrls so that it uses an URL pattern matching only the configured domains (except current domain) for preg_split with PREG_SPLIT_DELIM_CAPTURE flag, then perform fixUrl on each URL found (every other array entry) and imploding the array to return the content. The regex for splitting would be similar to the one in replaceDomain function ( In that way, fixUrl would be the only place where actual rewriting takes place, and instead of testing only for wp-admin we could test for any URLs/paths set in a filter or in the settings view on the admin GUI if you wanna expose that there. And as it would work on shorter and simpler strings, replaceDomain could use str_replace instead of preg_replace, or something like that. Not sure what performance impact those changes would have in general case, but if nothing needs to be replaced then only a preg_split will be done, instead of potentially many preg_replace (one per domain) that don't replace anything. Otoh when there are URLs to be fixed, there would be as many str_replace as URLs to be fixed, and the preg_split on top, instead of as many preg_replace's as domains configured (on a potentially large string). For now I will just rewrite back to the original domain with mod_rewrite anyway, but leaving this thought here 👍 Cheers |
@jffaria I've been running low on free time to update the plugin. I liked your idea and I'd love if you could submit a PR. Maybe at least a starting point to review and work together. Feel free to do that if you have a chance. In any case, I really appreciate your contribution to a possible solution! |
@straube okay, since you liked the idea I will try my hand at putting this into a PR in the next few days. Thanks for the feedback! |
Sometimes it may be useful to keep a URL as it is, not applying the rewriting. Here is a case the exemplifies a situation: https://wordpress.org/support/topic/linking-to-original-domain/.
I'm not sure if prepending something to the URL/domain is the best way to achieve that but it's one way.
Any other suggestions are welcome.
The text was updated successfully, but these errors were encountered: