如何重写由连字符分隔的 URL?
How to rewrite URLs split by hyphens?
我在用连字符写 URL 时感到困惑。它与 GET 参数冲突。
例如,我在 URL 中有一个很长的书名,空格被连字符代替,例如 the-famous-world-records-of-athletics
。在此之后我得到分页错误也用连字符分隔。
请建议我如何在给定阶段编写 URLs:
example.com/vc.php?book=the-famous-world-records-of-athletics
example.com/vc.php?book=the-famous-world-records-of-athletics&page=1
example.com/vc.php?book=the-famous-world-records-of-athleticstopic=jumping-and-racing&page=2
希望写作:
example.com/the-famous-world-records-of-athletics.html
example.com/the-famous-world-records-of-athletics-1.html
example.com/the-famous-world-records-of-athletics-jumping-and-racing-2.html
减号在URL中完全有效,即所谓的'unreserved'字符。
https://en.wikipedia.org/wiki/Percent-encoding
如果您真的需要替换它们,我会将它们替换为 %2D
,就像您将 space 替换为 %20
一样。
我在用连字符写 URL 时感到困惑。它与 GET 参数冲突。
例如,我在 URL 中有一个很长的书名,空格被连字符代替,例如 the-famous-world-records-of-athletics
。在此之后我得到分页错误也用连字符分隔。
请建议我如何在给定阶段编写 URLs:
example.com/vc.php?book=the-famous-world-records-of-athletics
example.com/vc.php?book=the-famous-world-records-of-athletics&page=1
example.com/vc.php?book=the-famous-world-records-of-athleticstopic=jumping-and-racing&page=2
希望写作:
example.com/the-famous-world-records-of-athletics.html
example.com/the-famous-world-records-of-athletics-1.html
example.com/the-famous-world-records-of-athletics-jumping-and-racing-2.html
减号在URL中完全有效,即所谓的'unreserved'字符。 https://en.wikipedia.org/wiki/Percent-encoding
如果您真的需要替换它们,我会将它们替换为 %2D
,就像您将 space 替换为 %20
一样。