简体   繁体   English

.htaccess url 路由怪异行为

[英].htaccess url routing weird behaviour

I have this in my .htaccess:我的 .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.如果是https://example.com/ ,那么语言将是默认值 (hu),但如果是https://example.com/en/ ,那么显然是 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:但是,在 page.php 上,如果 url 具有 en/(或 de/、fr/ 等)前缀,则路由变量会重复,例如:

//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.我不是最伟大的 regexologyst,所以非常感谢您的帮助,谢谢。

I solved the problem, after too many hours of research, basically i had to give a DPI flag to the first rule.我解决了这个问题,经过太多小时的研究,基本上我不得不给第一条规则一个 DPI 标志。 (Also QSA was unnecessary in my case) Like this: (在我的情况下也不需要 QSA)像这样:

RewriteRule ^en/?(.*)$ $1?lang=en [NC,DPI]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM