Screenload
Screenload

Reputation: 439

Redirect everything inside subdirectory but not subdirectory itself

I have a multilingual wordpress site that went live and replaces the old site.

Not every language is translated yet, so I want to keep the old site alongside wordpress for the other languages.

My .htaccess looks like this at the moment:

Redirect 302 /zh-hans/ /cn/
RedirectMatch 302 ^/(zh-hans)/. /cn/
Redirect 302 /ja/ /jp/
RedirectMatch 302 ^/(ja)/. /jp/
RedirectMatch 302 ^/(en)/. /en/

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

en, jp and cn are actual folders with index.html files in them. WordPress uses en, ja and zh-hans for these languages.

I have some problems with this:

  1. Only example.de/ja/ and example.de/zh-hans/ are working as intended
  2. example.de/ja (without ending slash) and all other language paths like that just redirect to example.de/
  3. example.de/en, example.de/en/ end up in a redirect loop
  4. everything that comes after and ending slash (example.de/ja/some-path) is opened by wordpress with a 404-page

At this point I have no idea how to handle this and I've tried different combinations for hours.

Is there even a way to handle this via .htaccess?

Upvotes: 2

Views: 44

Answers (1)

Amit Verma
Amit Verma

Reputation: 41219

Try replacing your Redirects with RewriteRules :

RewriteEngine on

RewriteRule ^zh-hans/?$ /cn/ [R,L]
RewriteRule ^(zh-hans)/. /cn/ [R,L]
RewriteRule ^ja/?$ /jp/ [R,L]
RewriteRule ^(ja)/. /jp/ [R,L]
RewriteRule ^en$ /en/ [L,R]

I also made the trailing slash optional in some specific patterns . It should work now.

Upvotes: 2

Related Questions