i'm not understanding what can be wrong. With the RewriteCond and RewriteRule to "beautify" my url, every time i swap language, insted of replacing, the code add one more. Like the example below
Example: https://testes.pt/pt/index.php
When swap to English: https://testes.pt/en/pt/index.php
When i switch to english again, (or other language)
https://testes.pt/en/en/pt/pt/index.php
The page still working and swap lang but have this bug
My htacess code:
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/+([^.]+\.php)\?lang=([^\s&]+) [NC]
RewriteRule ^ /%2/%1? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([A-Z]{2})/(.+?)/?$ /$2?lang=$1 [L,QSA,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([A-Z]{2})/?$ /?lang=$1 [L,QSA,NC]
The html code:
<li>
<a href="?lang=pt">PT</a>
</li>
<li>
<a href="?lang=en">EN</a>
</li>
Thank you