我有这样的网址...
https://localhost/index.php?com=liste-cat-lieux&t=41&l=6088
我需要改写成这样:
https://localhost/index.php?com=liste-cat-lieux&t=41&l=06088
我尝试追加前导0
RewriteCond %{QUERY_STRING} ^(com=liste-cat-lieux&t=\d{2,3}&l=)(\d{4})$
RewriteRule ^index\.php /index?%10%2 [R=301,L]
当我用https://htaccess.madewithlove.com/之类的工具测试它时,它看起来工作得很好,但实际上它在htaccess或apache中并不工作
1条答案
按热度按时间8i9zcol21#
您的重定向规则看起来正确,但有一个问题。它不检查现有前导零,这导致
0123
到00123
等等。我建议您保留您的重定向规则为:
这里,模式
[1-9]\d*
匹配参数值l
,该参数值以数字1到9开头,后跟0或更多数字。另请注意,在重定向URL中使用
/$0
,保持与RewriteRule
相同的匹配URI,即/index.php
。