Jump to content

Got home page instead of 404 when using urlSegments


Zeka
 Share

Recommended Posts

Hi!

I have this code in my page template file:

<?php namespace Processwire;

if($input->urlSegment2) throw new Wire404Exception();

if ($input->urlSegment(1)) {
	$pagename = $input->urlSegment(1);
	$p = pages()->findOne("template=knowledge-base-category|knowledge-base-item, name={$pagename}");
	if ($p->id) {
		$p->render();
	} else {
		throw new Wire404Exception();
	}
} else {
	$viewData["categories"] = pages("template=knowledge-base-category");
	region("content", renderView("knowledge-base", $viewData));
}
?>

Max urlSegments is set to 4.

Should URL segments end with trailing slash is set to Yes. 

Everything works as expected until I try to access any URL which ends with any special character like: 

site.com/current-page/real-page/not-real-page)

or

site.com/current-page/real-page/not-real-page@

In those cases, I get rendered homepage instead of 404 page.

Is there something obvious that I missed? 

  • Like 1
Link to comment
Share on other sites

1 minute ago, Zeka said:

Yes, when adding % I got "Bad request! Your browser (or proxy) sent a request that this server could not understand."

In my case the server hides the actual error message and only displays a false one. I did not dig further though.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...