Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8374911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:02:26+00:00 2026-06-09T15:02:26+00:00

I would like to redirect users that use a wrong querystring in the URL

  • 0

I would like to redirect users that use a wrong querystring in the URL to a custom error page while ALSO giving a 404 status through the .htaccess directive

ErrorDocument 404 http://www.domain.com/404.php

EDIT: this does not give 404 but 302!!! The “http://www.domain.com”
causes a redirect. Just the local path gives a 404. See also http://httpd.apache.org/docs/2.0/mod/core.html#errordocument

Therefore I made a script in the request-receiving index.php that determines if the querystring is not valid and if so, gives this command:

header("HTTP/1.0 404 Not Found");

BUT this does not redirect via the .htaccess directive ErrorDocument but just gives a 404 status to the visitor.

And when using header("Location: 404.php") you get a 302 status, and when using header("Location: 404.php", true, 404) the status is 404 but it does not go to the custom 404.php page.

Now I use

header ("Location: ", true, 404); 
echo "The URL you use doesn't lead to an existing page, etc.";

But this was not the original plan… How would I make users that use a wrong querystring in the URL redirect to the custom error page while also giving a 404 status through the .htaccess directive ErrorDocument, or is this not possible?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T15:02:28+00:00Added an answer on June 9, 2026 at 3:02 pm

    As far as I’m aware the only way to show the 404 page from PHP is to explicitly redirect to it. The reason is Apache (or whatever web server you’re using) has already successfully located a resource to which to direct the client (the PHP script being executed). If the PHP script can’t resolve the client’s request then it has to handle the sending of 404 headers and displaying the page itself.

    You could either redirect

    header ("HTTP/1.0 404 Not Found");
    header ('Location: http://' . $_SERVER["SERVER_NAME"] . '/404.php');
    

    Or you could include the 404 page into the PHP script that wants to trigger a 404.

    header ("HTTP/1.0 404 Not Found");
    include ('/path/to/404.php');
    

    EDIT: If you use the first technique (redirection) and want to pass the $_GET to the script so it can determine what’s wrong with it, you can do this.

    header ("HTTP/1.0 404 Not Found");
    header ('Location: http://' . $_SERVER["SERVER_NAME"] . '/404.php?' . http_build_query ($_GET));
    

    If you include the 404.php file then the $_GET will be available to it already

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to make it possible to redirect users from a site to
I would like to download a .CSV and redirect the user to another page.
I would like to redirect all requests, that coming to www.website.com/whatever to the variant
I would like to redirect visitors to a login page with added parameters (based
I would like to use graph API to get page and app insights without
I am using Rails 3.1.1 and I would like to redirect users, for example,
I would like to redirect my user to another domain. For example: my site
I would like to redirect the Debug stdout stream to a textblock. Is there
I would like to redirect as such... http://old.com/a/b/ -> http://new.com/y/z/ http://old.com/a/b/file.php -> http://new.com/y/z/ http://old.com/a/b/c/file.php
I would like to redirect all images to a showimage.php, using htaccess But if

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.