سؤال

I'm trying to redirect all pages that don't start with a locale to a page with a locale. For example: /index.htm is redirected to /en-US/index.htm, but /en-US/hello.htm isn't redirected anywhere.

I can't get the matching rule to work, this is what I tried:

!^/[a-z]{2}-[A-Z]{2}/$

Edit: jacouh was right, the thing worked the whole time, the rewrite rule was wrong, and so was my test.

هل كانت مفيدة؟

المحلول

I tested this in Debian/Apache2 in vhosts file:

RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}%{SCRIPT_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}%{SCRIPT_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/en-US/hello\.htm
RewriteRule !^/[a-z]{2}-[A-Z]{2}/ /en-US/hello.htm [R=301,L]

that works.

/en-US/hello.htm must exist, otherwise, an infinite loop of redirection is possible.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top