How can I strip subfolder with mod_rewrite

I'm deleting some translated content from my website, but I want redirect to the original language, the translated content url's are like this:

mydomain.com/es/mypage
mydomain.com/jp/mypage
mydomain.com/ko/mypage

And the original lang is like this:

mydomain.com/mypage

I was able to redirect to the original content using php, however I would like to do it in apache using mod_rewrite or RedirectMatch

Upvotes: 0

Views: 42

Answers (1)

Croises
Croises

Reputation: 18671

You can use this root .htaccess:

RewriteEngine on
RewriteRule ^(?:es|jp|ko)(/mypage)$ $1 [NC,R=301,L]

If you try to rewrite all the content for languages, you can use:

RewriteRule ^(?:es|jp|ko)(/.+)$ $1 [NC,R=301,L]

And for redirect also directories alone (ex: mydomain.com/es -> mydomain.com):

RewriteRule ^(?:es|jp|ko)(/.*)?$ $1 [NC,R=301,L]

Upvotes: 1

Related Questions