Status : 404 Not Found
18 posts by 2 authors in: Forums > CMS Builder
Last Post: January 7, 2008 (RSS)
By Dave - January 4, 2008
(contents_of_viewerUrl_field).php//(contents_of_viewerUrl_field)/
Try this (changing filename and removing extra slash):
blog.php/(contents_of_viewerUrl_field)/
The code should generate links like that already. It might have got changed during integration. If you get stuck on it attach your viewer file and I'll have a look. It seems to be working on my end correctly. Let me know how it goes.
interactivetools.com
Re: [Dave] Status : 404 Not Found
By Djulia - January 4, 2008
I modified the value of :
$pageLink = "{$_SERVER['PHP_SELF']}/{$menuRecord['pageurl']}/";
with
$pageLink = "/blog.php/{$menuRecord['pageurl']}/";
... and this functions it correctly. [:)]
2) I have a last adjustment.
I have the URL following :
http://www.xxx.com/blog.php/page_2/
It would be possible to redirect :
/blog.php/page_2 (without /[/#ff0000])
on :
blog.php/page_2/
Or, obtain an error 404 ?
It is a detail, but sometimes the sites make errors in the exchange of link (…)
Thank you Dave for your patience.
Julia
By Dave - January 6, 2008
If you see if you blog.php code the part that shows the 404:
// error if page not found
if (!$pageRecord) {
header("HTTP/1.1 404 Not Found");
...
That basically says, if we can't find a page, show the 404. We can add a line that checks if there is a / on the end of the url and show the 404 if there is no page -OR- if there is no slash on the end. Like this:
// error if page not found
$urlEndsWithSlash = preg_match("|/$|", @$_SERVER["PATH_INFO"]);
if (!$pageRecord || !$urlEndsWithSlash) {
header("HTTP/1.1 404 Not Found");
...
That will show the 404 for: /blog.php/page2 and also /blog.php since there is no slash on the end. You'd have to use /blog.php/.
If you want a 404 on any page without a slash EXCEPT "/blog.php" then you could use this:
// error if page not found
$urlEndsWithSlash = preg_match("|/$|", @$_SERVER["PATH_INFO"]);
$pageNameSetAndNoSlash = (@$_SERVER["PATH_INFO"] && !$urlEndsWithSlash);
if (!$pageRecord || $pageNameSetAndNoSlash) {
header("HTTP/1.1 404 Not Found");
...
The PHP preg_match() function used "regular expressions" to see if something matches a pattern. In this case, to see if the url ends in a slash. Anyway, hope that helps! :)
interactivetools.com
Re: [Dave] Status : 404 Not Found
By Djulia - January 6, 2008 - edited: January 6, 2008
Thank you, your code works marvelously. [:)]
I also noticed that blogPage or blogPage.php gives the same result.
/folder/blogPage[/#0080ff]/page1/
/folder/blogPage[/#0080ff].php[/#ff0000]/page1/
You think, that it is possible to obtain a result only for .../blogPage/...[/#0080ff] ?
Then, .../blogPage.php/... would give an error 404 ?
Thank you for your answer.
Julia
By Dave - January 6, 2008
Anyway, the script url is stored in $_SERVER["PHP_SELF"] so you can use the preg_match() function to check if there's a .php in the url.
$hasDotPHP = preg_match("/\.php/", $_SERVER['PHP_SELF']);
And then add that as "OR $hasDotPHP" to your 404 check:
$hasDotPHP = preg_match("/\.php/", $_SERVER['PHP_SELF']);
if (!$pageRecord || $pageNameSetAndNoSlash || $hasDotPHP) {
interactivetools.com
Re: [Dave] Status : 404 Not Found
By Djulia - January 6, 2008
But, you think, that one can use the two codes together ?
$urlEndsWithSlash = preg_match("|/$|", @$_SERVER["PATH_INFO"]);
if (!$pageRecord || !$urlEndsWithSlash) {
$hasDotPHP = preg_match("/\.php/", $_SERVER['PHP_SELF']);
if (!$pageRecord || $pageNameSetAndNoSlash || $hasDotPHP) {
I made several tests, but I do not manage to obtain a satisfactory result.
The idea, it is to obtain an error 404 for : /folder/blogPage.php[/#ff0000]/page/
and not for : /folder/blogPage/page/
But : /folder/blogPage/page
must also give an error 404.
Thank,
Julia
By Dave - January 6, 2008
PHP_SELF = '<?php echo $_SERVER['PHP_SELF']; ?>'
hasDotPHP = '<?php echo $hasDotPHP; ?>'
PHP_SELF should have the script url "/folder/blogPage.php/" and if it has ".php" in it then it should set $hasDotPHP. Then if you know it has ".php" you could display the 404. Checking for the .php shouldn't change how anything else is working.
interactivetools.com
Re: [Dave] Status : 404 Not Found
By Djulia - January 7, 2008
Your suggestion enabled me to correct my problem.
In fact, my server does not guarantee the use of : ( $_SERVER['PHP_SELF'] ).
In my case, it gives "/page1/" for "/folder/blogPage.php/page1/"
But, it seems that the use of ( $_SERVER['SCRIPT_NAME'] ) also works.
Thank you, you are a very good teacher.
Thank,
Julia