重写 url .htaccess GET-Parameter 用于目录路由

rewrite url .htaccess GET-Parameter for directory routing

我想在 .htaccess 中构建我的 url 如下 https://exmaple.com/index.php?lang=de-DE&path=/dir/subdir/https://example.com/de-DE/dir/subdir/ 但保留添加额外 GET 参数的能力。

对于目录,我尝试了这个但没有成功
RewriteEngine On
RewriteRule /(.+)$ /index.php?path= [L,QSA]

根据您显示的示例,您能否尝试以下操作。请确保在测试您的网址之前清除缓存。

RewriteEngine ON
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/([^/]*)/?$ index.php?lang=&path= [L]

或者根据 OP 的评论,使用 QSA 标志和 L 标志将先前传递的查询字符串附加到上述规则中新建的查询字符串。