Forum Moderators: phranque

Message Too Old, No Replies

adding ? to a page doesnt bring up 404

how to fail any non-exsisting page

         

santapaws

5:06 pm on Mar 2, 2009 (gmt 0)

10+ Year Member



not being a techy im not sure if this is an apache question or applied to any platform. I notice that for my appache sites adding ?to the end of a url and then adding any text after it doesnt bring up a 404, it just brings up the page that is listed before the ?.

for example
www.example.com/?test.htm brings up www.example.com/ but with ?test.htm at the end. Seems an easy way to get into duplicate penalty territory if someone decides to link to the page that way, maliciously or not.

Why doesnt this result in a 404? and whats the best was to rectify this?

rocknbil

4:35 pm on Mar 3, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It doesn't 404 because by adding the ? it doesn't change the URL, it populates the environment variable QUERY_STRING and makes it available to the page. It's just that the static page doesn't do anything with it.

Give you an example: script "test.cgi" (pseudo code, leaving out the part that reads and parses the query string:)

URL 1: http://example.com/test.cgi
URL 2: http://example.com/test.cgi?v=Hello+World

#!/usr/bin/perl

## "parse_query_string" stores variables in key-value pairs in "%invar"

%invar = &parse_query_string;

print "content-type:text/html\n\n";
if (defined($invar{'v'})) { print "$invar{'v'}"; }
else { print "No variable sent"; }

URL 1 will print "No variable sent" and URL 2 will print "Hello World."

Both are the same url, one has a query string, one doesn't.

When you sent this syntax to a static page, the URL is the same.