I want to write a RewriteRule that both cleans the URL and puts the language detection before the file.
I have looked at questions like .htaccess for language detection, redirecting + clean urls and .htaccess rule for language detection.
With these two combined I made a solution that sometimes works and sometimes doesn't.
My structure: domain.com/subfolder/news.php?lang=en
What I want is: domain.com/subfolder/en/news
My code so far:
RewriteBase /subfolder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Language Detection
RewriteRule ^(en|sv)/(.*)$ $2?lang=$1 [QSA,L]
## Remove .php extensions
RewriteRule ^([^\.]+)$ $1.php [NC,L]`
This did work on some paths, but not on all (they had the same structure).
How should I solve this?