I have made a website in with Magento in one language 2 years ago and now I would like to add another language.
My actual structure is like that 

* example.com/category/
* example.com/about.html
* example.com/product.html

and I would like to obtain a structure like this:

* example.com/lang1/category/
* example.com/lang1/about.html
* example.com/lang1/product.html
* example.com/lang2/category/
* example.com/lang2/about.html
* example.com/lang2/product.html

This is not a big deal since Magento allowes me us to do that simply logging in the backend ->System -> Configuration -> Web -> Add store code to Urls (YES)

I can't do this setting right now because before that I need to fix and do rewrites from the first structure to the new one.

* example.com/everything\_without\_the\_/lang1/\_path to a permanent
* example.com/lang1/everything

I need for example that the urls from the backlinks from posts from the socials and other webistes won't get a 404 error but will automatically be redirected with a 301 redirection to the equivalent page in the new structure.

So I would like to add a script like this in the natural language:

```
rewrite permanently all the urls which ends not with /lang1/ or /lang2/ to urls with the prefix /lang1/

```

I know that I could manually add rewrite rules with this schema in the Magento backend but I would prefer to know if it is possible to batch this directly from the database or with some script in the .htaccess or index.php and above all which one between these solutions will have a less negative impact in SEO and SERP. 

---

I've found a solution

Hi I've found a solution:

```
    RewriteCond %{HTTP_HOST} ^(.)?example.com$ [NC] 
    RewriteCond %{REQUEST_URI} !^/it/
    RewriteCond %{REQUEST_URI} !^/en/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /it/$1  [R=301,L]
    RewriteCond %{HTTP_HOST} ^(.)?example.com$ [NC]
    RewriteRule ^(/)?$ it/index.php [L]

```

at a first look works, but I not guarantee. 
I hope this will help
Cheers