Skip to content
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

Compatibility with wpml #153

Open
262media opened this issue Mar 22, 2018 · 5 comments
Open

Compatibility with wpml #153

262media opened this issue Mar 22, 2018 · 5 comments
Labels
help wanted type:bug Something isn’t working.

Comments

@262media
Copy link

I can't make this play along with wpml. maybe because wpml creates virtual directories(ex: /fr/ , /pt/ don't really exist on the server) or any other issue ...
But the fact is that my 301 redirects that include one of this virtual directories results in a 404.
I'm using NGINX (powered by trellis and bedrock).

Anyone have a clue?
Thanks in advance
Rui

@braders
Copy link
Contributor

braders commented Aug 29, 2018

We have recently had to solve this problem. We found there were 3 steps required to get this working properly:

  • We setup the redirects CPT as a translatable post type, and redirects were added to the correct language. When adding the redirects for a subdomain language the language code was commited (e.g. for example.com/es/ the /es/ part was ommited from the redirect paths).
  • SRM assumes that subdomain installations will not have a trailing slash when using home_url, whereas WPML will add a trailing slash. We had to use the srm_registered_redirects filter to intentionally break the URL normalisation. (We also used this filter to add proper support for escaped characters, such as Chinese or Japanese kanji)
  • Lastly, we had to use WP filters so that the _srm_redirects transient was stored internally as different transients per language. (specifically with the pre_set_transient__srm_redirects, transient__srm_redirects and delete_transient__srm_redirects) filters.

@chelder86
Copy link

Same issue here (WPML is very popular!). Could you share the exact code to add to functions.php please? It would be incredible helpful for me...

@jeffpaul jeffpaul added the type:bug Something isn’t working. label Jun 24, 2019
@jeffpaul jeffpaul added this to the 2.0.0 milestone Jun 24, 2019
jameswburke pushed a commit to alleyinteractive/safe-redirect-manager that referenced this issue Jul 24, 2019
…_responsive

onsomething: Adding Yoast SEO (wordpress-seo) plugin
@jeffpaul jeffpaul modified the milestones: 1.10.0, 2.0.0 Nov 23, 2020
@teachmeter
Copy link

teachmeter commented Feb 1, 2022

Plugin version: 1.10.0

I've had a simmilar issue.
We are using WPML + some custom rewrite rules. The plugin works as expected and catches a link like
/example/some-slug but it has problems with /fr/otherexample/some-other-slug

to actually fix it I've frozen the plugin source for our case and applied this piece of code in class-srm-redirect.php

$matchesLangCode = preg_match('/^(\/[a-zA-Z]{2}\/)$/m', $parsed_home_url['path']) === 1;
if ( isset( $parsed_home_url['path'] ) && '/' !== $parsed_home_url['path'] && ! $matchesLangCode ) {
    $requested_path = preg_replace( '@' . $parsed_home_url['path'] . '@i', '', $requested_path, 1 );
}

Basically what it does is to not fully delete the requested path if it has a language code.

Otherwise the $requested_path for /fr/something/else becomes empty and it doesn't match properly as it searches something/else/ instead of /fr/something/else which is stored in the db.

I haven't run any tests for it or thoroughly check other cases but this might be a hint for somebody else.

@jeffpaul
Copy link
Member

@CPROps @jameswburke looks like you may have crafted a downstream fix, mind pushing that upstream here for others to benefit from?

@jeffpaul jeffpaul modified the milestones: 2.0.0, Future Release Jun 28, 2022
@slothluvchunk
Copy link

@jeffpaul - We (CPR) don't have a downstream fork of this repo that I can see, but it's possible that we inherited something along the way. You may want to check with whomever is maintaining AlleyInteractive's fork.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted type:bug Something isn’t working.
Projects
None yet
Development

No branches or pull requests

6 participants