wordpress custom redirection
-
Greetings!
We currently have a wordpress blog with a translation plugin that we don’t like at all. We are switching to WPML. The issue is that the actual bad plugin has translated all the posts with language code in the url like this:
/es_ES/ for spanish
/en_US/ for english
/pt_BR/ for portuguese
and the WPML plugin uses a different code languages:/es/ for spanish
(nothing) for english, because is the default language on my site
/pt/ for portugueseWPML does allows to create custom languages, so we could create variations for those languages, and create our own language codes that match the actual/old plugin, but I am thinking that it might be a better or more elegant solution to use the default WPML codes, and just redirect the old URL’s to the new ones.
So, for example, let’s say a user enters an old url for a post:
https://genexus.blog/es_ES/genexus-platform/18-news-about-genexus-18/
I would like to create a custom redirection rule that redirects the user in this case, to the same url, but modifying the code part only, to martch WPML code:
https://genexus.blog/es/genexus-platform/18-news-about-genexus-18/
So what I did is ask chat-gpt to give me a .htaccess redirect rule:
RewriteRule ^(.*)/es_ES/(.*)$ $1/es/$2 [R=301,L]This didn’t work. When I tried to go to :
https://genexus.blog/es_ES/genexus-platform/18-news-about-genexus-18/
WordPress redirected to me to the default post url, with is english :
18 news about GeneXus 18
I then asked WPML support if the plugin was may be doing some kind of custom redirection, and they told me that it could be WordPress. I did some Google and find out that WordPress has some redirection functions like this ones:
- redirect_canonical()
- redirect_guess_404_permalink()
The first one is very important for SEO, and disabling this function could hurt the blog SEO.
The recomendation seems to be to disable the other function: redirect_guess_404_permalink()
https://typerocket.com/disable-wordpress-automatic-or-random-redirect-guessing-of-404s/redirect_guess_404_permalink()is a function that looks for similar URLs registered in WordPress and will redirect old URLs to those it can find. This feature is nice to have for SEO if you are not keeping an eye on your 404 pages but can create some weird redirect behavior. That might be why you found this post interesting… you need your redirects to be more predictable.But then I thougt, may be, instead of disabling that function, and doing my custom redirect on .htacess, I could use WordPress to create my custon redirection, and forget about tweaking .htacces
So, to round up, my question is: Can I customize
redirect_guess_404_permalink() function to do what I need? That is, redirect my current urls /es_ES/ to my new urls /es/.If that is possibe, I would appreciate any techy Wordpres developer to shed some light on me.
Thanks in advance.
The blog I need help with is: (visible only to logged in users)
-
Hi there,
One thing to be aware of is that unlike other hosts (most hosts?) we do not use Apache web servers, which is the kind of web server that uses .htaccess files. This is why the code provide by GPT will not work for your site.
Instead we use a custom managed hosting environment (based on nginx) that is optimized for the needs of WordPress. It’s not possible to edit the .htaccess file (we don’t use them) and it is also not possible to set up redirects at the server level.
However, the good news is that you can instead use a redirection plugin to help you manage our redirects, and from what I understand most plugins that I’ve seen will let you use regular expressions as well.
https://wordpress.com/plugins/?s=redirection
Hope that helps. Please let us know if you have any more questions.
- The topic ‘wordpress custom redirection’ is closed to new replies.