如何重定向 URL,然后使用 htaccess 将其重写为相同的 url?

How to redirect a URL and then rewrite it to same url with htaccess?

有 PHP 文件重定向到

header("location:./exchange?title=".$directionin. '_'. $directionto);

我想重写这个URL localhost/moneyworld/exchange?title=BTC_PMUSD 对此 localhost/moneyworld/BTC_PMUSD 我试过了

RewriteEngine On
RewriteRule ^([^/]*)\.html$ /moneyworld/exchange?title= [L]

然后我将 .htaccess 文件放在根目录中,但它不起作用,然后我将它放在 moneyworld 文件夹中,但它也不起作用。

能否请您尝试以下操作(根据您显示的示例),如果您正在寻找 rewrite/redirect 从 localhost/moneyworld/exchange?title=BTC_PMUSDlocalhost/moneyworld/BTC_PMUSD URL 然后尝试以下操作

RewriteEngine ON
RewriteCond %{THE_REQUEST} \s/(moneyworld)/exchange\?title=([^\s]*)\s [NC]
RewriteRule ^ /%1/%2 [NE,QSD,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([^/]+)/?$ /moneyworld/exchange?title= [L]