WordPress中的个人评论url,用于跨web的URI集成


Individual comment URLs in WordPress for URI integration across the web

我一直在开发一个评论系统(反向工程WordPress)。就我而言,我希望社交网络上的每条评论都是难以处理的。这意味着它们需要自己的URL。我构建了一个页面(comment.php),并将评论的ID存储为get参数。

问题是社交网络删除了get参数,以便他们可以将自己的数据存储在其中。

然后我使用页码系统作为评论id将其构建到URL中,然后使用str_replace获得我们想要的评论id。(即example.com/comment/135)。这是有效的,但社交网络删除了页码部分。如果数字后面有一个字母,他们不会删除它们。

因此,我正在寻找一种拥有个人评论页面的方式。我已经制作了一个主题文件并准备好了,但我只需要一个标准的注释URL。像example.com/comment/135-comment/这样的东西,它有自己的页面,可以从URI中提取ID。如何做到这一点?

您可以使用htaccess规则将example.com/comment/135-comment重写为example.com/comment/?id=135

但这只会在你有响应的情况下起作用。url中的注释模板example.com/comment/

RewriteEngine On
RewriteBase /
RewriteRule ^comment/([0-9]+)-comment/$ http://example.com/comment/?id=$1 [L]
RewriteRule ^index'.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

一种通用的方法是使用类似example.com/123-post/135-comment/的帖子id和评论id。

RewriteEngine On
RewriteBase /
RewriteRule ^([0-9]+)-post/([0-9]+)-comment/$ http://example.com/?p=$1#comment-$2 [L]
RewriteRule ^index'.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]