Php 不带查询字符串的重定向301

Php 不带查询字符串的重定向301,php,.htaccess,redirect,mod-rewrite,Php,.htaccess,Redirect,Mod Rewrite,我正在尝试将一个url重定向到一个新的。 例如: 到 在.htaccess中,我有以下代码: Redirect 301 /dir/552-hi.html https://www.example.com/new.html RewriteEngine On RewriteRule ^/dir/552-hi.html https://www.example.com/new.html? [L,R=301] 而且效果很好。但它添加了如下查询字符串: https://www.example.com/ne

我正在尝试将一个url重定向到一个新的。 例如:

在.htaccess中,我有以下代码:

Redirect 301 /dir/552-hi.html https://www.example.com/new.html
RewriteEngine On
RewriteRule ^/dir/552-hi.html https://www.example.com/new.html? [L,R=301]
而且效果很好。但它添加了如下查询字符串:

https://www.example.com/new.html?id=552
我在Stackoverflow搜索了很多,找到了以下代码:

Redirect 301 /dir/552-hi.html https://www.example.com/new.html
RewriteEngine On
RewriteRule ^/dir/552-hi.html https://www.example.com/new.html? [L,R=301]
但是我不能让它工作。现在重定向没有重定向。
有人知道我必须做什么吗?

在你的根目录中这样尝试

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^dir/([\d]+)-hi.html$ new.html?id=$1 [R=301,QSA,L]