Ad

Htaccess Negation

- 1 answer

I use htaccess to parse seo-friendly requests. Earlier my htaccess had these string to parse requests like /some/request/

RewriteCond %{REQUEST_URI} !index.php
RewriteRule ^([^.]*)$ /index.php?alias=$1 [QSA]

Now I have multilingual support on my site to parse requests like /en/some/request/

RewriteCond %{REQUEST_URI} !index.php
RewriteRule ^(en|de)(/)?([^.]*)$ /index.php?lng=$1&alias=$3 [QSA]

How to catch all old request without language part /some/request/ and forward them to default language /en/some/request/

As I understand it should by something like it

RewriteCond %{REQUEST_URI} !^(en|de)
RewriteRule ^(.?)$ ru/$1/ [L,R=301]
Ad

Answer

You can try your rules this way.

RewriteEngine On
RewriteRule ^(?!en|de)/?(.+)$ /en/$1 [R=301,L]

RewriteRule ^index\.php - [L]
RewriteRule ^(en|de)/?([^.]*)$ /index.php?lng=$1&alias=$2 [QSA,L]
Ad
source: stackoverflow.com
Ad