htaccess index.php?id=value 到 /value.html

htacces index.php?id=value to /value.html

我想用 htaccess 更改 2 个 url 应该很容易,但我很难用它:

index.php?id=Agenda/agenda.html?id=Agenda 也到 /agenda.html

我试过了

RewriteRule ^(.*[^/])/?$ index.php?id=  [L,NC]

还有一些变体,但我无法让它发挥作用,有什么建议吗?

您可以在 DOCUMENT_ROOT/.htaccess 文件中使用此代码:

RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} /(?:index\.php)?\?id=(.+?)\s [NC]
RewriteRule ^ %1.html? [R=302,L,NE]

# internal forward from pretty URL to actual one
RewriteRule ^([^.]+)\.html$ ?id= [L,QSA,NC]