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

htacces index.php?id=value to/value.html,php,.htaccess,url-rewriting,Php,.htaccess,Url Rewriting,我有两个我想用htaccess更改的URL应该很容易,但我很难做到: index.php?id=Agenda至/Agenda.html 和 ?id=Agenda也可转到/Agenda.html 我试过了 RewriteRule ^(.*[^/])/?$ index.php?id=$1 [L,NC] 和它的一些变体,但我无法让它工作任何建议?您可以在文档中使用此代码。\u ROOT/.htaccess文件: RewriteEngine On RewriteBase / RewriteCond

我有两个我想用htaccess更改的URL应该很容易,但我很难做到:

index.php?id=Agenda
/Agenda.html
?id=Agenda
也可转到
/Agenda.html

我试过了

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

和它的一些变体,但我无法让它工作任何建议?

您可以在
文档中使用此代码。\u 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=$1 [L,QSA,NC]

抱歉在我的问题中犯了一个错误,因为不止一个url:所以这里的议程是需要更改的值之一示例:index.php?id=value,但对于议程来说,它是有效的:)这就像一个符咒:)我的代码出了什么问题?(我想从错误中吸取教训;)。另外,我如何在代码中添加%2(空格),例如?id=room%201?您的规则在regex模式中没有
.html
,您可以看到您需要两条规则,而不是一条。若要允许空间,两个规则都将更改(请参阅更新的规则),但请不要在注释中添加新问题。总是最好开始一个新问题。谢谢你下次会记得:)太感谢你的建议和帮助了!