如何使用.htaccess替换请求参数名称?

时间:2019-04-18 10:19:20

标签: apache .htaccess

我想重写部分URL,例如:

/api/posts?topic.id=246&pagination=false

/api/posts?postTopics.topic.id=246&pagination=false

topic.id => postTopics.topic.id

请帮助。

1 个答案:

答案 0 :(得分:0)

RewriteEngine on
RewriteCond %{QUERY_STRING} !postTopics.topic.id=
RewriteCond %{QUERY_STRING} ^(.*)topic.id=([0-9]*)(.*)$
RewriteRule ^ %{REQUEST_URI}?%1postTopics.topic.id=%2%3 [QSD,NE]