0

I spend few hours thinking under one problem.

I making frendly url for some application, and it works fine with this cond:

RewriteEngine On
RewriteRule ^/shop/([a-z]*)/([a-záéíóúüñç]*)-([a-záéíóúüñç]*)$ /carga.php?car=$3&model=$2&type=buy&lang=$1&other=$4 [QSA]

after that url loks like that:

example.com/shop/spanish/m3-bmw?other=somevar

but the main problem is that application must receive language in 2 letters format, for example, es,en,ru shortly speaking - somehow it must go from url to application in that format. Now i see that applicatin receives full word from url.

So at the moment url looks like that:

example.com/shop/spanish/m3-bmw?other=somevar

But application needs like that:

example.com/shop/es/m3-bmw?other=somevar

thank you in advance

1 Answer 1

1

According to what you say you want, you just need this:

RewriteEngine On
RewriteRule ^/shop/([a-z]{2})[a-z]*/([a-záéíóúüñç]*)-([a-záéíóúüñç]*)$ /carga.php?car=$3&model=$2&type=buy&lang=$1&other=$4 [QSA]

But I am not sure it can work for all languages if the language code is not the first 2 letters for instance.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, it worked perfectly! And yes, you are right that it will not work for all languages, because according ISO standarts, for example, the code of spanish is "es", but in english it will be "sp" from "spanish" with this rewrite. But it is just homework that make no sense and i only need to make it work according the exercise. Anyway, it could be useful for other tasks. For language detect, in my opinion, better to use RewriteCond %{HTTP:Accept-Language} or detect language by application.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.