如何通过 htaccess 将 id 重写为名称
How do I rewrite an id to a name via htaccess
我正在尝试通过 htaccess 重写标题 ID,但它不起作用。我在 htaccess 中使用了几种不同的代码,但它不起作用。
当我按名称访问 url 时,它没有显示任何 post,但使用 ID 时效果很好。
我在 htaccess 中使用这段代码:
RewriteRule ^([0-9a-z]+)/?$ news-details.php?nid= [NC,L,QSA]
posts/categories 的 ID:
127.0.0.1/new/news-details.php?nid=89
127.0.0.1/new/category.php?catid=9
Yes it works through the id "/new/89" you mentioned but not with url "/new/89/name-news"
然后更改规则(正则表达式)以允许 /<id>/<slug>
(没有尾部斜杠),例如:
RewriteRule ^(\d+/[\w-]+)$ news-details.php?nid= [NC,L,QSA]
<id>/<slug>
然后作为 nid
URL 参数的值过去。
我正在尝试通过 htaccess 重写标题 ID,但它不起作用。我在 htaccess 中使用了几种不同的代码,但它不起作用。 当我按名称访问 url 时,它没有显示任何 post,但使用 ID 时效果很好。
我在 htaccess 中使用这段代码:
RewriteRule ^([0-9a-z]+)/?$ news-details.php?nid= [NC,L,QSA]
posts/categories 的 ID:
127.0.0.1/new/news-details.php?nid=89
127.0.0.1/new/category.php?catid=9
Yes it works through the id "/new/89" you mentioned but not with url "/new/89/name-news"
然后更改规则(正则表达式)以允许 /<id>/<slug>
(没有尾部斜杠),例如:
RewriteRule ^(\d+/[\w-]+)$ news-details.php?nid= [NC,L,QSA]
<id>/<slug>
然后作为 nid
URL 参数的值过去。