404 page based on query string?

  • 1
  • Question
  • Updated 7 years ago
  • Answered
I understand this question isn't likely possible with Yola, that's alright, I need it for a site hosted outside of Yola. I tend to get much better assistance here at Yola and must be searching Google wrong because I can't find the answer. Php knowledge is likely required to answer this question. I basically want to know how I can provide search suggestions based on the wrong url or search the user entered in from. If someone can tell me that I would be greatly appreciated, or if you can guide me in the right direction to find the answer. Thanks very much!
Photo of Donald

Donald

  • 2991 Posts
  • 37 Reply Likes
  • http://youcanneverbetoosmart.com

Posted 7 years ago

  • 1
Photo of Donald

Donald

  • 2991 Posts
  • 37 Reply Likes
Photo of Nathan

Nathan, Champion

  • 3739 Posts
  • 307 Reply Likes
Hi Donald,

Maybe this will help: http://dev-tips.com/featured/php-tip-...

You can get the URL requested with:


<?php
$url = $_SERVER['REQUEST_URI'];
?>


So, in the URL you posted, $url would equal /Book_Catalog/fadflk.php

You could strip out the symbols and '.php' with:


<?php
$url = $_SERVER['REQUEST_URI'];
$url = str_replace('/',' ', $url);
$url = str_replace('_', ' ', $url);
$url = str_replace('.php','', $url);
?>


This would now return Book Catalog fadflk.

Then you can echo $url into the form:


<form method="post" action="querygoogle.php">
<label for="searchquery">
<span class="caption">Search this site</span>
<input type="text" size="20" maxlength="255" title="Enter your keywords and click the search button" name="searchquery" value="<?php echo $url; ?>" />
</label>
<input type="submit" value="Search" />
</form>


Now when you go the 404 page, it will have the search query in the box already, and the search query will be the page requested.

I hope this helps.
Photo of Sanja

Sanja, Official Rep

  • 10698 Posts
  • 495 Reply Likes
Thanks for your assistance on this Nathan!
Photo of Donald

Donald

  • 2991 Posts
  • 37 Reply Likes
Just wondering, it ain't that big of deal, but would be nice. Is there anyway to strip out everything before the actual filename?

Book_Catalog/this_file.php

Book_Catalog is the directory and this_file.php is the file. Now, I found out how to strip out Book_Catalog by using "Book" "_" and "Catalog" in each of their str_replace, however, the problem with that, if Book or Catalog show up anywhere in the filename, it strips it there as well. Hopefully, there's a magic code to separate the directory from the filename, I was looking into preg_replace, but didn't quite get that resolved. Thanks! :)
Photo of Nathan

Nathan, Champion

  • 3739 Posts
  • 307 Reply Likes
@Sanja: No problem!
@Donald: I don't know about that, but I'll see what I can do. I'm sure it will be something different than replace. Maybe there is a way to request just the file name and not the directory structure?
Photo of Donald

Donald

  • 2991 Posts
  • 37 Reply Likes
That looks like it'll work, I'll try that, Thanks!
Photo of Donald

Donald

  • 2991 Posts
  • 37 Reply Likes
ok, great, so far so good, now if only I can figure a way for spelling variations I'll be all set. Look what I did... http://youcanneverbetoosmart.com/Book...

I echoed the $url in my site search link and provided a link to search throughout the site.