Rewrite URL if file exists

Posted by Anthony Faull on Stack Overflow See other posts from Stack Overflow or by Anthony Faull
Published on 2010-06-10T07:48:36Z Indexed on 2010/06/10 8:22 UTC
Read the original article Hit count: 279

Filed under:
|

I need to redirect web requests of the form /{language}-{country}/{file} to:

  1. /{language}-{country}/{file} if it exists, otherwise
  2. /{language}/{file} if it exists, otherwise
  3. /en-US/{file}

The existing .htaccess fulfils requirements 1 and 3. What changes do I need to fulfil requirement 2?

.htaccess:

Options +FollowSymLinks
RewriteEngine On
RewriteCond $0 !i18n/en-US [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(i18n)/([^/]+)/(.*)$ $1/en-US/$3 [NC,L]

© Stack Overflow or respective owner

Related posts about .htaccess

Related posts about mod-rewrite