I need a redirect from
https://example.com/shop/vip-schmuck/18-karat-gold/18-karat-gold-nasenstecker-spirale-schmetterling-kristalle/
to
https://example.com/shop/vip-schmuck/18-karat-gold/280419/18-karat-gold-nasenstecker-spirale-schmetterling-kristalle/
what means 1 is the old URL und 2 is the new one.
The only change is the "280419" in the new URL.
UPDATE:
I want to redirect all of my product URLs. ie. from example.com/shop/placeholderhere/placeholderhere/placeholderhere/
to example.com/shop/placeholderhere/placeholderhere/280419/placeholderhere/
CodePudding user response:
At the top of your root .htaccess
file you can do something like this:
RewriteRule ^(shop/vip-schmuck/18-karat-gold)/(18-karat-gold-nasenstecker-spirale-schmetterling-kristalle/)$ /$1/280419/$2 [R=302,L]
The $1
and $2
backreferences in the substitution string (2nd argument) contain the values captured from the parenthesised subpatterns in the preceding RewriteRule
pattern. This simply saves repetition (and potential error).
This is a 302 (temporary) redirect. Only change to a 301 (permanent) redirect - if that is the intention - once you have confirmed this works as intended.
Reference:
UPDATE:
i want to redirect alll of my producs , what means old protect-
example.com/shop/placeholderhere/placeholderhere/placeholderhere/
to protect-example.com/shop/placeholderhere/placeholderhere/280419/placeholderhere/
To inject the code 280419
in every URL that follows that format you can do something like this instead:
RewriteRule ^(shop/[^/] /[^/] )/([^/] )/?$ /$1/280419/$2/ [R=302,L]
Where $1
contains the URL-path that matches the first subpattern (shop/[^/] /[^/] )
and $2
matches the last path segment (excluding an optional trailing slash) as denoted by ([^/] )/?$
. The trailing slash is enforced on the target URL.