Search code examples
wordpress.htaccesshttp-redirectmod-alias

htaccess + wordpress not working


I'm working with updated WP and I'm trying to redirect old url to new url:

Redirect 301 /es/ http://www.example.com
Redirect 301 /es/tienda/ http://www.example.com
Redirect 301 /es/categoria-producto/quillas/center http://www.example.com/categoria/quillas-single/

And this is what I got in the browser:

If I try to access to the first URL I got a redirect to:

http://www.example.comtienda/

Yes, It's missing the slash.

And If I try to access the other URL I got a redirect to:

http://www.example.com/categoria-producto/quillas/center/

Which is a 404...

So, I migrated the website thinking about server error but the problem persists...

What am I doing wrong?


Solution

  • Redirect 301 /es/ http://www.example.com
    Redirect 301 /es/tienda/ http://www.example.com
    Redirect 301 /es/categoria-producto/quillas/center http://www.example.com/categoria/quillas-single/
    

    Since the mod_alias Redirect directive is prefix matching, you would need to reverse these directives. But you are missing the slash on the end of the target URL, so that's why the slash is missing. So, for example:

    Redirect 301 /es/categoria-producto/quillas/center/ http://www.example.com/categoria/quillas-single/
    Redirect 301 /es/tienda/ http://www.example.com/
    Redirect 301 /es/ http://www.example.com/
    

    If you have a slash on the source URL, you should include a slash on the target.

    However, since this is a WordPress site, you should be using mod_rewrite instead. For example, before your existing WP directives:

    RewriteRule ^es/categoria-producto/quillas/center$ /categoria/quillas-single/ [R=301,L]
    RewriteRule ^es/tienda/$ / [R=301,L]
    RewriteRule ^es/$ / [R=301,L]
    

    In this case the order of the directives does not matter.