I have a problem with .htaccess rules:
I want to redirect this url:
/productos/ficha/carretillas-termicas/dx.html
To this one:
/productos/ficha/carretillas-termicas/grendia-es-serie-fd20-35n3.html
I'm using this .htaccess rule:
Redirect 301 /productos/ficha/carretillas-termicas/dx.html /productos/ficha/carretillas-termicas/grendia-es-serie-fd20-35n3.html
But the server redirects to:
/productos/ficha/carretillas-termicas/grendia-es-serie-fd20-35n3.html?catalogo=carretillas-termicas&slug=gx
Notice the arregation of params "?catalogo=carretillas-termicas&slug=gx"
Both URL's are the same:
/productos/ficha/carretillas-termicas/grendia-es-serie-fd20-35n3.html?catalogo=carretillas-termicas&slug=gx
/productos/ficha/carretillas-termicas/grendia-es-serie-fd20-35n3.html
So, I want to delete the params to avoid two different URL's with the same content (a SEO problem)
The .htaccess rule that generate the "productos" URL's is this:
# Converts urls like:
# productos_ficha.php?catalogo=XXX&slug=YYY
# to
# productos/ficha/XXX/YYY.html
RewriteRule ^(.*)/(.*)/(.*)/(.*).html$ $1_$2.php?catalogo=$3&slug=$4 [L]
I tried some of the solutions I found in this site, but they does not works for my case. Thank you a lot.
(From the URL and rule you've posted you should be seeing
slug=dx, notslug=gx?)You have a conflict between the mod_alias
Redirectdirective and the mod_rewriteRewriteRule. mod_rewrite is processed before mod_alias (despite the apparent order of the directives) and rewrites the request, appending the query string. TheRedirectthen issues a redirect on the original URL-path, but appends the rewritten query string.Instead of using mod_alias
Redirectdirective, you need to use a mod_rewriteRewriteRuleinstead to perform the redirect. And this must go _before_mthe existing rewrite.For example:
To save repetition I captured the URL-path in the first rule (redirect) and used the corresponding backreference
$1in the substitition string.I also modified the regex in the second rule (rewrite) since it was far to general and very inefficient (requiring a lot of backtracking).