去掉 ”?”从查询字符串

Remove "?" from the query string

我决定放弃 Wordpress 转而使用 Pico CMS

现在我正在努力正确地完成 URL 重写。

我已经成功地重写了来自 eg 的查询字符串。 https://www.example.org?pagehttps://www.example.org/page 使用 RewriteRule ^(.*) ? [L],但现在如果 查询字符串,我也想重写它。

示例:

如果请求 https://www.example.org?page 它加载得很好,但我想将它重写为 https://www.example.org/page - 至少在地址栏中。

我尝试了多种变体,但无济于事。我很讨厌正则表达式...

RewriteCond %{QUERY_STRING} !^$ RewriteRule ^\?/(.*)$

没有

RewriteRule (^\?$) https://tanghus.net/ [NC,R=301,L] RewriteRule ^.*$ https://tanghus.net/? [NC,R=301,L]

没有骰子

RewriteCond %{QUERY_STRING} . RewriteRule ^$ %{QUERY_STRING} [R,L]

RewriteCond %{THE_REQUEST} \?\sHTTP [NC] RewriteRule ^ %{REQUEST_URI} [L,R]

放弃:(

你可以使用这个规则

RewriteEngine on

# externally  redirect from /?page to /page
RewriteCond %{THE_REQUEST} /\?([^\s]+) [NC]
RewriteRule ^/?$ /%1? [L,R]
# internally map /page to /?page
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/?(.+)$ /? [L]