I’m trying to write a rule for my .htaccess file that checks for a match on the 1st path segment, checks that the last segment !=en, and then replaces the last segment.
e.g.
convert
/zh/something/somethingelse/de/
into
/zh/something/somethingelse/en/
If the last segment is already /en/ the rule doesn’t need to be applied.
There can be more or less path segments in between the first and last.
I’m trying this at the moment
RewriteRule /zh.*/([^/]+)/(?!^en$).*$ /zh/$1/en/ [R=301,L]
but it is giving me
/zh/en/en/
as the result
Maybe change the regex and add the condition to prevent looping on
/en/:Note: if this is being used in an .htaccess file and you’re using apache 2.0+, you need to remove the leading slash from
^/zhto^zh.