重定向循环(URL重写)

Redirection loop (URL rewriting)

我正在尝试重写我的网站 URL。我有:

http:// website.com/v2/message.php?ID2=123

我要:

http:// website.com/v2/message-123.php

我在我的 htaccess 中尝试了一些东西,但我有一个重定向循环:'(

这是我的 .htaccess:

RewriteCond %{QUERY_STRING} ^ID2=([0-9]+)$
RewriteRule message.php? http://website.com/v2/message-%1.php? [L,R=301]

有人可以帮我解决这个问题吗?

我建议不要在漂亮的 URL 中使用 .php,使其无扩展名。在 v2/.htaccess 中尝试这些规则:

RewriteEngine On
RewriteBase /v2/

RewriteCond %{THE_REQUEST} /message\.php\?ID2=([^&\s]+) [NC]
RewriteRule ^ message-%1? [NE,R=302,L]

RewriteRule ^message-(.+)/?$ message.php?ID2= [L,QSA,NC]