1

我如何 Comprobe 找不到 404?

这是我的代码 php:

$id = $_GET['id'];
$slug = "my-slugified-title-post-in-this-example"; // Slug is dinamic according to id

echo "This post is here!";

这是我的 htaccess

RewriteRule ^posts/([0-9]+)/(.*?).html post.php?id=$1$slug=$2 [L,NC]

如果 url 中的 $slug 错误,我想要 404 错误:

http://mysite.com/posts/274/my-slugified-title-post-wrong-in-this-example.html //slug is wrong

这没关系!

http://mysite.com/posts/274/my-slugified-title-post-in-this-example.html
4

1 回答 1

1

如果 slug 是错误的,您必须将其与从 id 中提取的 slug 进行比较。所以在你的 php 脚本中,你会有类似的东西:

$id = $_GET['id'];
$slug = "my-slugified-title-post-in-this-example"; // Slug is dinamic according to id

if ( $slug != $_GET['slug'] ) {   // slug is different
    header('HTTP/1.0 404 Not Found');
    exit();
}

echo "This post is here!";
于 2013-10-17T04:45:38.533 回答