php - .htaccess url routing weird behaviour
Get the solution ↓↓↓I have this in my .htaccess:
RewriteRule ^en/?(.*)$ $1?lang=en [QSA]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ page.php?route=$1 [NC,L,QSA]
The task would be to get the language paramater. If it's https://example.com/, then language will be the default (hu), but if it's https://example.com/en/, then it's obviously en. This part works fine. However, on page.php, the route variable gets duplicated if url has the en/ (or de/, fr/, etc..) prefix, for example:
//https://example.com/en/air-conditioners
$_GET['route'] = 'air-conditioners/air-conditioners'; //вќЊ
$_GET['lang'] = 'en'; //вњ”
//https://example.com/en/air-conditioners/
$_GET['route'] = 'air-conditioners//air-conditioners/'; //вќЊ
$_GET['lang'] = 'en'; //вњ”
I'm not the greatest regexologyst, so help would be really appreciated, thanks.
Answer
Solution:
I solved the problem, after too many hours of research, basically i had to give a DPI flag to the first rule. (Also QSA was unnecessary in my case) Like this:
RewriteRule ^en/?(.*)$ $1?lang=en [NC,DPI]
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: php undefined array key
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.