473,395 Members | 1,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Help: If isset query_string return 404

wd
I want my server to send a 404 header if a URL with a query string is
requested. So if a browser or spider requests something
like
www. my_site .com?p=chair
they would get a 404...

But if they request
www. my_site .com/chair.htm
everything would be normal.

With some assistance this is what I have so far, but it isn't working
correctly. It always displays the 404, even when there is no question
mark in the URL. Also, I would like the page to stop displaying anything
after the "HTML>>>" if it sends the 404 error, but I'm not sure how to do
it:
if (isset($_SERVER["QUERY_STRING"])) {
header("HTTP/1.0 404 Not Found");
echo <<<HTML

<head>
<title>404 Not Found</title>
</head>
<body>
<h1>Not Found</h1>
The requested URL was not found on this server.
</body>
</html>

HTML>>>;

}

Jan 17 '06 #1
25 2463
d
"wd" <n2*@nospam.invalid> wrote in message
news:pa****************************@nospam.invalid ...
I want my server to send a 404 header if a URL with a query string is
requested. So if a browser or spider requests something
like
www. my_site .com?p=chair
they would get a 404...

But if they request
www. my_site .com/chair.htm
everything would be normal.

With some assistance this is what I have so far, but it isn't working
correctly. It always displays the 404, even when there is no question
mark in the URL. Also, I would like the page to stop displaying anything
after the "HTML>>>" if it sends the 404 error, but I'm not sure how to do
it:
if (isset($_SERVER["QUERY_STRING"])) {
header("HTTP/1.0 404 Not Found");
echo <<<HTML

<head>
<title>404 Not Found</title>
</head>
<body>
<h1>Not Found</h1>
The requested URL was not found on this server.
</body>
</html>

HTML>>>;

}


That's because $_SERVER["QUERY_STRING"] is *always* set, regardless of
whether there's a query string or not. You might want to compare it to an
empty string, or check its length. Checking whether it's set or not does
not check the content at all...

dave
Jan 17 '06 #2
wd
On Tue, 17 Jan 2006 12:06:45 +0000, d wrote:
"wd" <n2*@nospam.invalid> wrote in message
news:pa****************************@nospam.invalid ...
I want my server to send a 404 header if a URL with a query string is
requested. So if a browser or spider requests something
like
www. my_site .com?p=chair
they would get a 404...

But if they request
www. my_site .com/chair.htm
everything would be normal.

With some assistance this is what I have so far, but it isn't working
correctly. It always displays the 404, even when there is no question
mark in the URL. Also, I would like the page to stop displaying anything
after the "HTML>>>" if it sends the 404 error, but I'm not sure how to do
it:
if (isset($_SERVER["QUERY_STRING"])) {
header("HTTP/1.0 404 Not Found");
echo <<<HTML

<head>
<title>404 Not Found</title>
</head>
<body>
<h1>Not Found</h1>
The requested URL was not found on this server.
</body>
</html>

HTML>>>;

}


That's because $_SERVER["QUERY_STRING"] is *always* set, regardless of
whether there's a query string or not. You might want to compare it to an
empty string, or check its length. Checking whether it's set or not does
not check the content at all...

dave


So, the query_string just contains the URL that is requested? Could I
just see if the query_string contains a question mark and then send the
404 if a question mark is found?

Jan 17 '06 #3
"wd" <n2*@nospam.invalid> wrote in message
news:pa****************************@nospam.invalid ...
I want my server to send a 404 header if a URL with a query string is
requested. So if a browser or spider requests something
like
www. my_site .com?p=chair
they would get a 404...

But if they request
www. my_site .com/chair.htm
everything would be normal.

With some assistance this is what I have so far, but it isn't working
correctly. It always displays the 404, even when there is no question
mark in the URL. Also, I would like the page to stop displaying anything
after the "HTML>>>" if it sends the 404 error, but I'm not sure how to do
it:
if (isset($_SERVER["QUERY_STRING"])) {

Try something like if(sizeof($_GET)){...

--
"En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirviö
sp**@outolempi.net | Gedoon-S @ IRCnet | rot13(xv***@bhgbyrzcv.arg)
Jan 17 '06 #4
d
"wd" <n2*@nospam.invalid> wrote in message
news:pa****************************@nospam.invalid ...
On Tue, 17 Jan 2006 12:06:45 +0000, d wrote:
"wd" <n2*@nospam.invalid> wrote in message
news:pa****************************@nospam.invalid ...
I want my server to send a 404 header if a URL with a query string is
requested. So if a browser or spider requests something
like
www. my_site .com?p=chair
they would get a 404...

But if they request
www. my_site .com/chair.htm
everything would be normal.

With some assistance this is what I have so far, but it isn't working
correctly. It always displays the 404, even when there is no question
mark in the URL. Also, I would like the page to stop displaying
anything
after the "HTML>>>" if it sends the 404 error, but I'm not sure how to
do
it:
if (isset($_SERVER["QUERY_STRING"])) {
header("HTTP/1.0 404 Not Found");
echo <<<HTML

<head>
<title>404 Not Found</title>
</head>
<body>
<h1>Not Found</h1>
The requested URL was not found on this server.
</body>
</html>

HTML>>>;

}


That's because $_SERVER["QUERY_STRING"] is *always* set, regardless of
whether there's a query string or not. You might want to compare it to
an
empty string, or check its length. Checking whether it's set or not does
not check the content at all...

dave


So, the query_string just contains the URL that is requested? Could I
just see if the query_string contains a question mark and then send the
404 if a question mark is found?


No, $_SERVER["QUERY_STRING"] is empty when there is no query string. If
there is a query string, say the page is:

http://somesite.com/?something

then $_SERVER["QUERY_STRING"]=="something". Check to see if the string is
empty, and if it is empty, then you're OK. If it's not empty, then a query
string has been passed.

dave
Jan 17 '06 #5
d
"Kimmo Laine" <sp**@outolempi.net> wrote in message
news:Dl*****************@reader1.news.jippii.net.. .
"wd" <n2*@nospam.invalid> wrote in message
news:pa****************************@nospam.invalid ...
I want my server to send a 404 header if a URL with a query string is
requested. So if a browser or spider requests something
like
www. my_site .com?p=chair
they would get a 404...

But if they request
www. my_site .com/chair.htm
everything would be normal.

With some assistance this is what I have so far, but it isn't working
correctly. It always displays the 404, even when there is no question
mark in the URL. Also, I would like the page to stop displaying anything
after the "HTML>>>" if it sends the 404 error, but I'm not sure how to do
it:
if (isset($_SERVER["QUERY_STRING"])) {

Try something like if(sizeof($_GET)){...


Just do this:

if ($_SERVER["QUERY_STRING"]=="") {
// OK
} else {
// Query string present
}
--
"En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirviö
sp**@outolempi.net | Gedoon-S @ IRCnet | rot13(xv***@bhgbyrzcv.arg)

Jan 17 '06 #6
d
"d" <d@example.com> wrote in message
news:yf****************@text.news.blueyonder.co.uk ...
"wd" <n2*@nospam.invalid> wrote in message
news:pa****************************@nospam.invalid ...
On Tue, 17 Jan 2006 12:06:45 +0000, d wrote:
"wd" <n2*@nospam.invalid> wrote in message
news:pa****************************@nospam.invalid ...
I want my server to send a 404 header if a URL with a query string is
requested. So if a browser or spider requests something
like
www. my_site .com?p=chair
they would get a 404...

But if they request
www. my_site .com/chair.htm
everything would be normal.

With some assistance this is what I have so far, but it isn't working
correctly. It always displays the 404, even when there is no question
mark in the URL. Also, I would like the page to stop displaying
anything
after the "HTML>>>" if it sends the 404 error, but I'm not sure how to
do
it:
if (isset($_SERVER["QUERY_STRING"])) {
header("HTTP/1.0 404 Not Found");
echo <<<HTML

<head>
<title>404 Not Found</title>
</head>
<body>
<h1>Not Found</h1>
The requested URL was not found on this server.
</body>
</html>

HTML>>>;

}

That's because $_SERVER["QUERY_STRING"] is *always* set, regardless of
whether there's a query string or not. You might want to compare it to
an
empty string, or check its length. Checking whether it's set or not
does
not check the content at all...

dave


So, the query_string just contains the URL that is requested? Could I
just see if the query_string contains a question mark and then send the
404 if a question mark is found?


No, $_SERVER["QUERY_STRING"] is empty when there is no query string. If
there is a query string, say the page is:

http://somesite.com/?something

then $_SERVER["QUERY_STRING"]=="something". Check to see if the string is
empty, and if it is empty, then you're OK. If it's not empty, then a
query string has been passed.

dave


You can also use the empty() function, which upon reading has been quicker
for some people than a straight comparison, not that comparisons are
notoriously lenghthy in their execution, but even so... ;)
Jan 17 '06 #7
d wrote:
"wd" <n2*@nospam.invalid> wrote in message
news:pa****************************@nospam.invalid ...
I want my server to send a 404 header if a URL with a query string is
requested. So if a browser or spider requests something
like
www. my_site .com?p=chair
they would get a 404...

But if they request
www. my_site .com/chair.htm
everything would be normal.

With some assistance this is what I have so far, but it isn't working
correctly. It always displays the 404, even when there is no question
mark in the URL. Also, I would like the page to stop displaying anything
after the "HTML>>>" if it sends the 404 error, but I'm not sure how to do
it:

if (isset($_SERVER["QUERY_STRING"])) {
header("HTTP/1.0 404 Not Found");

[snip]
That's because $_SERVER["QUERY_STRING"] is *always* set, regardless of
whether there's a query string or not.


Not true. With apache, QUERY_STRING will always be set; however, with
other web server software (ie. MS IIS) it will never be set unless you
have done so yourself.

Therefore, to be more portable, you may want to do something more like this:

if(isset($_GET) && is_array($_GET) && count($_GET)){
header("HTTP/1.0 404 Not Found");
echo <<< HTML
<html>
<head>
<title>404 Not Found</title>
</head>
<body>
<h1>Not Found</h1>
The requested URL was not found on this server.
</body>
</html>
HTML;
exit;
}

--
Justin Koivisto, ZCE - ju****@koivi.com
http://koivi.com
Jan 17 '06 #8
d
"Justin Koivisto" <ju****@koivi.com> wrote in message
news:8f********************@onvoy.com...
d wrote:
"wd" <n2*@nospam.invalid> wrote in message
news:pa****************************@nospam.invalid ...
I want my server to send a 404 header if a URL with a query string is
requested. So if a browser or spider requests something
like
www. my_site .com?p=chair
they would get a 404...

But if they request
www. my_site .com/chair.htm
everything would be normal.

With some assistance this is what I have so far, but it isn't working
correctly. It always displays the 404, even when there is no question
mark in the URL. Also, I would like the page to stop displaying
anything
after the "HTML>>>" if it sends the 404 error, but I'm not sure how to
do
it:

if (isset($_SERVER["QUERY_STRING"])) {
header("HTTP/1.0 404 Not Found");

[snip]
That's because $_SERVER["QUERY_STRING"] is *always* set, regardless of
whether there's a query string or not.


Not true. With apache, QUERY_STRING will always be set; however, with
other web server software (ie. MS IIS) it will never be set unless you
have done so yourself.


Incorrect. I tested it with Apache and IIS. BOTH have
$_SERVER["QUERY_STRING"] set regardless of whether a query string is present
or not.
Therefore, to be more portable, you may want to do something more like
this:

if(isset($_GET) && is_array($_GET) && count($_GET)){
header("HTTP/1.0 404 Not Found");
echo <<< HTML
<html>
<head>
<title>404 Not Found</title>
</head>
<body>
<h1>Not Found</h1>
The requested URL was not found on this server.
</body>
</html>
HTML;
exit;
}
I don't want to sound rude, but that's ridiculous. Just check to see if
$_SERVER["QUERY_STRING"] is a non-empty string. If it is, then hey-presto,
you're set. You don't need to call isset, is_array and count all in one go.
--
Justin Koivisto, ZCE - ju****@koivi.com
http://koivi.com

Jan 17 '06 #9
d
"Justin Koivisto" <ju****@koivi.com> wrote in message
news:8f********************@onvoy.com...
d wrote:
"wd" <n2*@nospam.invalid> wrote in message
news:pa****************************@nospam.invalid ...
I want my server to send a 404 header if a URL with a query string is
requested. So if a browser or spider requests something
like
www. my_site .com?p=chair
they would get a 404...

But if they request
www. my_site .com/chair.htm
everything would be normal.

With some assistance this is what I have so far, but it isn't working
correctly. It always displays the 404, even when there is no question
mark in the URL. Also, I would like the page to stop displaying
anything
after the "HTML>>>" if it sends the 404 error, but I'm not sure how to
do
it:

if (isset($_SERVER["QUERY_STRING"])) {
header("HTTP/1.0 404 Not Found");

[snip]
That's because $_SERVER["QUERY_STRING"] is *always* set, regardless of
whether there's a query string or not.


Not true. With apache, QUERY_STRING will always be set; however, with
other web server software (ie. MS IIS) it will never be set unless you
have done so yourself.


I turned off a module in our engine, and you are correct - IIS won't set
QUERY_STRING unless prompted to. Regardless, it still doesn't merit calling
isset, is_array, and count just to check whether a string is empty or not.
Therefore, to be more portable, you may want to do something more like
this:

if(isset($_GET) && is_array($_GET) && count($_GET)){
header("HTTP/1.0 404 Not Found");
echo <<< HTML
<html>
<head>
<title>404 Not Found</title>
</head>
<body>
<h1>Not Found</h1>
The requested URL was not found on this server.
</body>
</html>
HTML;
exit;
}

--
Justin Koivisto, ZCE - ju****@koivi.com
http://koivi.com

Jan 17 '06 #10
d
"Justin Koivisto" <ju****@koivi.com> wrote in message
news:8f********************@onvoy.com...
d wrote:
"wd" <n2*@nospam.invalid> wrote in message
news:pa****************************@nospam.invalid ...
I want my server to send a 404 header if a URL with a query string is
requested. So if a browser or spider requests something
like
www. my_site .com?p=chair
they would get a 404...

But if they request
www. my_site .com/chair.htm
everything would be normal.

With some assistance this is what I have so far, but it isn't working
correctly. It always displays the 404, even when there is no question
mark in the URL. Also, I would like the page to stop displaying
anything
after the "HTML>>>" if it sends the 404 error, but I'm not sure how to
do
it:

if (isset($_SERVER["QUERY_STRING"])) {
header("HTTP/1.0 404 Not Found");

[snip]
That's because $_SERVER["QUERY_STRING"] is *always* set, regardless of
whether there's a query string or not.


Not true. With apache, QUERY_STRING will always be set; however, with
other web server software (ie. MS IIS) it will never be set unless you
have done so yourself.

Therefore, to be more portable, you may want to do something more like
this:


And not to mention your method only works if the query string is actually a
string of get parameters. If you pass just a string (as in his example),
the $_GET array is empty....
if(isset($_GET) && is_array($_GET) && count($_GET)){
header("HTTP/1.0 404 Not Found");
echo <<< HTML
<html>
<head>
<title>404 Not Found</title>
</head>
<body>
<h1>Not Found</h1>
The requested URL was not found on this server.
</body>
</html>
HTML;
exit;
}

--
Justin Koivisto, ZCE - ju****@koivi.com
http://koivi.com

Jan 17 '06 #11
d wrote:
"Justin Koivisto" <ju****@koivi.com> wrote in message
news:8f********************@onvoy.com...
d wrote:
"wd" <n2*@nospam.invalid> wrote in message
news:pa****************************@nospam.invalid ...
I want my server to send a 404 header if a URL with a query string is
requested. So if a browser or spider requests something
like
www. my_site .com?p=chair
they would get a 404...

But if they request
www. my_site .com/chair.htm
everything would be normal.

With some assistance this is what I have so far, but it isn't working
correctly. It always displays the 404, even when there is no question
mark in the URL. Also, I would like the page to stop displaying
anything
after the "HTML>>>" if it sends the 404 error, but I'm not sure how to
do
it:

if (isset($_SERVER["QUERY_STRING"])) {
header("HTTP/1.0 404 Not Found"); [snip]
That's because $_SERVER["QUERY_STRING"] is *always* set, regardless of
whether there's a query string or not.

Not true. With apache, QUERY_STRING will always be set; however, with
other web server software (ie. MS IIS) it will never be set unless you
have done so yourself.


Incorrect. I tested it with Apache and IIS. BOTH have
$_SERVER["QUERY_STRING"] set regardless of whether a query string is present
or not.


Just because your IIS server has it does not mean that is the default.
My install (and every other install that I have used) does not *ever*
have it set. My version is (as reported by $_SERVER['SERVER_SOFTWARE'])
"Microsoft-IIS/5.1"
Therefore, to be more portable, you may want to do something more like
this:

if(isset($_GET) && is_array($_GET) && count($_GET)){
header("HTTP/1.0 404 Not Found");
echo <<< HTML
<html>
<head>
<title>404 Not Found</title>
</head>
<body>
<h1>Not Found</h1>
The requested URL was not found on this server.
</body>
</html>
HTML;
exit;
}


I don't want to sound rude, but that's ridiculous.


....but you just did.
Just check to see if
$_SERVER["QUERY_STRING"] is a non-empty string. If it is, then hey-presto,
you're set. You don't need to call isset, is_array and count all in one go.


And then when you install to another server like Netscape? Zues? AOL?
Roxen? thttpd? The list goes on. You cannot *expect* a server to have
$_SERVER['QUERY_STRING'] set in all cases.

--
Justin Koivisto, ZCE - ju****@koivi.com
http://koivi.com
Jan 17 '06 #12
d
"Justin Koivisto" <ju****@koivi.com> wrote in message
news:3-********************@onvoy.com...
d wrote:
"Justin Koivisto" <ju****@koivi.com> wrote in message
news:8f********************@onvoy.com...
d wrote:
"wd" <n2*@nospam.invalid> wrote in message
news:pa****************************@nospam.invalid ...
> I want my server to send a 404 header if a URL with a query string is
> requested. So if a browser or spider requests something
> like
> www. my_site .com?p=chair
> they would get a 404...
>
> But if they request
> www. my_site .com/chair.htm
> everything would be normal.
>
> With some assistance this is what I have so far, but it isn't working
> correctly. It always displays the 404, even when there is no question
> mark in the URL. Also, I would like the page to stop displaying
> anything
> after the "HTML>>>" if it sends the 404 error, but I'm not sure how to
> do
> it:
>
> if (isset($_SERVER["QUERY_STRING"])) {
> header("HTTP/1.0 404 Not Found");
[snip]

That's because $_SERVER["QUERY_STRING"] is *always* set, regardless of
whether there's a query string or not.
Not true. With apache, QUERY_STRING will always be set; however, with
other web server software (ie. MS IIS) it will never be set unless you
have done so yourself.


Incorrect. I tested it with Apache and IIS. BOTH have
$_SERVER["QUERY_STRING"] set regardless of whether a query string is
present
or not.


Just because your IIS server has it does not mean that is the default.
My install (and every other install that I have used) does not *ever*
have it set. My version is (as reported by $_SERVER['SERVER_SOFTWARE'])
"Microsoft-IIS/5.1"


See my other posts.
Therefore, to be more portable, you may want to do something more like
this:

if(isset($_GET) && is_array($_GET) && count($_GET)){
header("HTTP/1.0 404 Not Found");
echo <<< HTML
<html>
<head>
<title>404 Not Found</title>
</head>
<body>
<h1>Not Found</h1>
The requested URL was not found on this server.
</body>
</html>
HTML;
exit;
}


I don't want to sound rude, but that's ridiculous.


...but you just did.
Just check to see if
$_SERVER["QUERY_STRING"] is a non-empty string. If it is, then
hey-presto,
you're set. You don't need to call isset, is_array and count all in one
go.


And then when you install to another server like Netscape? Zues? AOL?
Roxen? thttpd? The list goes on. You cannot *expect* a server to have
$_SERVER['QUERY_STRING'] set in all cases.

--
Justin Koivisto, ZCE - ju****@koivi.com
http://koivi.com

Jan 17 '06 #13
d wrote:

And not to mention your method only works if the query string is actually a
string of get parameters. If you pass just a string (as in his example),
the $_GET array is empty....


What are you talking about? If you request:
example.com/page.php?mystring

Then the $_GET array will be:
array(
'mystring' => ""
)

--
Justin Koivisto, ZCE - ju****@koivi.com
http://koivi.com
Jan 17 '06 #14
d
"Justin Koivisto" <ju****@koivi.com> wrote in message
news:uu******************************@onvoy.com...
d wrote:

And not to mention your method only works if the query string is actually
a
string of get parameters. If you pass just a string (as in his example),
the $_GET array is empty....
What are you talking about? If you request:
example.com/page.php?mystring

Then the $_GET array will be:
array(
'mystring' => ""
)


I guess we have differing setups. Either way, your assertion of portability
is out of the window ;)
--
Justin Koivisto, ZCE - ju****@koivi.com
http://koivi.com

Jan 17 '06 #15
d wrote:

I turned off a module in our engine, and you are correct - IIS won't set
QUERY_STRING unless prompted to. Regardless, it still doesn't merit calling
isset, is_array, and count just to check whether a string is empty or not.


It's not a string, it's an array. To each their own on how to check. I
just like to be complete - it gives less chance of bugs down the road.
When you've been doing full-time php development for 6 years, then you
can criticize my merit of how I do things.

--
Justin Koivisto, ZCE - ju****@koivi.com
http://koivi.com
Jan 17 '06 #16
d wrote:
"Justin Koivisto" <ju****@koivi.com> wrote in message
news:uu******************************@onvoy.com...
d wrote:
And not to mention your method only works if the query string is actually
a
string of get parameters. If you pass just a string (as in his example),
the $_GET array is empty....

What are you talking about? If you request:
example.com/page.php?mystring

Then the $_GET array will be:
array(
'mystring' => ""
)


I guess we have differing setups. Either way, your assertion of portability
is out of the window ;)


*PLONK*

--
Justin Koivisto, ZCE - ju****@koivi.com
http://koivi.com
Jan 17 '06 #17
d
"Justin Koivisto" <ju****@koivi.com> wrote in message
news:ve********************@onvoy.com...
d wrote:

I turned off a module in our engine, and you are correct - IIS won't set
QUERY_STRING unless prompted to. Regardless, it still doesn't merit
calling
isset, is_array, and count just to check whether a string is empty or
not.
It's not a string, it's an array. To each their own on how to check. I
just like to be complete - it gives less chance of bugs down the road.
When you've been doing full-time php development for 6 years, then you
can criticize my merit of how I do things.


The $_SERVER["QUERY_STRING"] is a string. Checking an array constructed
from the contents of a string is pointless - just check the string. If you
want to use a mixture of constructs and functions to determine the
characteristics of an array over just checking whether a string is empty,
then go right ahead.

And, funnily enough, I've been coding PHP professionally "full-time" for 7
years, so it seems I can criticise the merit of how you do things. Thanks
for letting me know ;)

--
Justin Koivisto, ZCE - ju****@koivi.com
http://koivi.com

Jan 17 '06 #18
d
"Justin Koivisto" <ju****@koivi.com> wrote in message
news:ve********************@onvoy.com...
d wrote:
"Justin Koivisto" <ju****@koivi.com> wrote in message
news:uu******************************@onvoy.com...
d wrote:
And not to mention your method only works if the query string is
actually
a
string of get parameters. If you pass just a string (as in his
example),
the $_GET array is empty....
What are you talking about? If you request:
example.com/page.php?mystring

Then the $_GET array will be:
array(
'mystring' => ""
)
I guess we have differing setups. Either way, your assertion of
portability
is out of the window ;)


*PLONK*


Hardly.
--
Justin Koivisto, ZCE - ju****@koivi.com
http://koivi.com

Jan 17 '06 #19
d wrote:

And, funnily enough, I've been coding PHP professionally "full-time" for 7
years, so it seems I can criticise the merit of how you do things. Thanks
for letting me know ;)


and I bet you've been using the native session support for 7 years as
well...

--
Justin Koivisto, ZCE - ju****@koivi.com
http://koivi.com
Jan 17 '06 #20
d
"Justin Koivisto" <ju****@koivi.com> wrote in message
news:be********************@onvoy.com...
d wrote:

And, funnily enough, I've been coding PHP professionally "full-time" for
7
years, so it seems I can criticise the merit of how you do things.
Thanks
for letting me know ;)
and I bet you've been using the native session support for 7 years as
well...


Nice try ;) Session handling didn't come along until php4, as you well
know.
--
Justin Koivisto, ZCE - ju****@koivi.com
http://koivi.com

Jan 17 '06 #21
wd
I just wanted to follow up on this thread. I finally got a chance to try
the recommended solutions and neither of the works.

I have an .htaccess file rewriting the URLs. So even though it looks like
the browser is visiting http://www.my_site.com/page1.html, PHP still
thinks the $_SERVER["QUERY_STRING"] is p=page1 (from
http://www.my_site.com/index.php?p=page1).

So every page except the home page ends up as a 404 not found error.

In the end, this solution worked -- PHP reads the URL and looks for a
question mark:

<?php
$url_string = $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
if (strstr($url_string, '?')) {
header("HTTP/1.0 404 Not Found");
echo <<<HTML
<html>
<head>
<title>404 Not Found</title>
</head>
<body>
<h1>Not Found</h1>
The requested URL was not found on this server.
</body>
</html>
HTML;
exit;
}
?>
Feb 18 '06 #22
Following on from wd's message. . .

Is 404 the most suitable 400-series status code?

--
PETER FOX Not the same since the bottom fell out of the bucket business
pe******@eminent.demon.co.uk.not.this.bit.no.html
2 Tees Close, Witham, Essex.
Gravity beer in Essex <http://www.eminent.demon.co.uk>
Feb 18 '06 #23
wd
On Sat, 18 Feb 2006 18:59:10 +0000, Peter Fox wrote:
Following on from wd's message. . .

Is 404 the most suitable 400-series status code?


It would either have to be 404 or 410. Google spidered about 250 URLs on
the site that have duplicate content like this:

http://www. my_site .com/index.php?p=12345
http://www. my_site .com/index.php?p=23456
http://www. my_site .com/index.php?p=239fj
http://www. my_site .com/index.php?p=29fks
http://www. my_site .com/index.php?p=20fks

I need those kinds of pages removed from Google's cache. Those pages
don't exist so Google thinks there are 250 web pages with the same content
as the home page. The site is being penalized because of it. From what
I've read on Google's webmaster guidelines, Google will only remove them
if it finds a 404 error message. Apparently, a 410 header will work also.

Feb 19 '06 #24
Following on from wd's message. . .
On Sat, 18 Feb 2006 18:59:10 +0000, Peter Fox wrote:
Following on from wd's message. . .

Is 404 the most suitable 400-series status code?


It would either have to be 404 or 410. Google spidered about 250 URLs on
the site that have duplicate content like this:

http://www. my_site .com/index.php?p=12345
http://www. my_site .com/index.php?p=23456
http://www. my_site .com/index.php?p=239fj
http://www. my_site .com/index.php?p=29fks
http://www. my_site .com/index.php?p=20fks

I need those kinds of pages removed from Google's cache. Those pages
don't exist so Google thinks there are 250 web pages with the same content
as the home page. The site is being penalized because of it. From what
I've read on Google's webmaster guidelines, Google will only remove them
if it finds a 404 error message. Apparently, a 410 header will work also.


Ooo err!

Shouldn't you be returning 404 if foo doesn't exist when asked for with
index.php?p=foo rather than any ?p=... ? What happens if Joe Bloggs
types in one of the offending ?p=... or a valid ?p=... How do you
distinguish those cases?



--
PETER FOX Not the same since the bottom fell out of the bucket business
pe******@eminent.demon.co.uk.not.this.bit.no.html
2 Tees Close, Witham, Essex.
Gravity beer in Essex <http://www.eminent.demon.co.uk>
Feb 19 '06 #25
wd
On Sun, 19 Feb 2006 00:47:41 +0000, Peter Fox wrote:
Ooo err!

Shouldn't you be returning 404 if foo doesn't exist when asked for with
index.php?p=foo rather than any ?p=... ? What happens if Joe Bloggs
types in one of the offending ?p=... or a valid ?p=... How do you
distinguish those cases?


No need... .htaccess rewrites all urls for legitimate pages. If you ask
for anything with a ? in the URL you now get a 404. If you ask for the
rewritten URLs (no question mark), you get the correct pages.
Mar 1 '06 #26

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: laurie | last post by:
Hi all, I'm trying to help out a friend who has inherited a client with a PHP shopping cart application. Neither of us know PHP, but I've been muddling my way through, trying to get these old...
2
by: Will | last post by:
How would you translate the following script into something that would work with register globals set to 'off'? --- $envs = array("HTTP_REFERER", "HTTP_USER_AGENT", "REMOTE_ADDR",...
5
by: ToMeK | last post by:
Hi! i have php page that displays records from mysql base. on that page i have link like this: <a href="mypage.php?option1">option1</a> ("option1" is name of one of my tables in db) now...
3
by: Dynamo | last post by:
Hi I have used the following script within a simple form email to prevent the form being used from an external url. <?php $referer = $_SERVER; // Get the URL of this page $myurl=...
2
by: dalsoth | last post by:
Hi Guys I have created a website and to makes things easier i decided to use dreamweaver to do the secure login section and access levels for the pages. When testing locally on wamp my website...
2
by: Adam Baker | last post by:
I'm not sure whether the following is a problem with PHP or my Apache server. Minimal example: <?php if (isset($dummy)) echo "Set."; else echo "Not set."; echo...
6
by: ruraldev | last post by:
I have been trying my best to display a chosen date as dd-mm-yyyy but insert it into the mysql database as yyyy-mm-dd, I know it must be simple but no matter what I try I can't get it to work. At...
1
by: wizardry | last post by:
hello - i'm inserting into varchar through php/html form but the data is posting in the database as 0 or null. thanks in advacance for your help. here is all the code: <?php
4
by: mattehz | last post by:
Hey there, I am trying to upload old source files and came across these errors: Warning: Invalid argument supplied for foreach() in /home/mattehz/public_html/acssr/trunk/inc_html.php on line 59...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.