基本上,如果它们是 URL 中代表查询参数的正确数量的 URI 段,则您只想显示一个有效页面。
URI segments
在调用任何其他方法之前,您应该检查作为预处理的数量。这样您就可以确定 URL 中实际上只有 1 个段
如果您发现您URL
的.
您可以检查 URL 中正确的段数,如果不是您想要的,则调用该show_404()
方法。
在您发布的示例 URL:
http://myweburl/Everything/gov/2/order.txt
中,实际上有 4 个段。
// from the docs http://codeigniter.com/user_guide/libraries/uri.html
$total_segments = $this->uri->total_segments();
// 3 segments would be the max if this is your url:
// http://myweburl/Everything/gov/2/order.txt (this url contains 4 segments)
// ^controller/function/uri_segment
// this means that there are 3 segments in your URL
// you don't want to have more than 3, so check for that
// with the total_segments() function
if($total_segments > 3)
{
$valid = false;
show_404();
}
else
{
$valid = true;
}
if($valid)
{
// process data as usual
}