mmosel Posted July 10, 2006 Share Posted July 10, 2006 I discovered a strange quirk with my site. If I add a slash after a script name, such as index.php/, then my page will show up but with no formating or style sheet, just a white page with text.Does anyone know why this happens? What might be a way to prevent this? Quote Link to comment Share on other sites More sharing options...
Prismatic Posted July 10, 2006 Share Posted July 10, 2006 Yeah dont put a slash at the end Quote Link to comment Share on other sites More sharing options...
mmosel Posted July 10, 2006 Author Share Posted July 10, 2006 It's not me I'm worried about. It's my visitors. I wouldn't want anyone to see my site like that, without images or style sheets applied. There must be a way to solve this problem. Quote Link to comment Share on other sites More sharing options...
redarrow Posted July 10, 2006 Share Posted July 10, 2006 Show more code why are you applying a slash to the end index.php/ Quote Link to comment Share on other sites More sharing options...
mmosel Posted July 10, 2006 Author Share Posted July 10, 2006 I'm not applying a slash after index.php file, but if I do, I get the error. Sometimes people play around with URLs and i don't want my site to show up as text only if someone messes with the URL. Quote Link to comment Share on other sites More sharing options...
ShogunWarrior Posted July 10, 2006 Share Posted July 10, 2006 I think that it may be that when you put a slash the server looks for the folder /page.php/which doesn't exist.So, it returns the 404 page which is your page except that the browser thinks the page URL is /page.php/page.php which means that the URLs of the images/styles will be incorrect.My conclusion is that your 404 page should redirect to the main page which will display correctly. Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted July 10, 2006 Share Posted July 10, 2006 seems a little pointless, but:[code]<?php$self = $_SERVER["PHP_SELF"];if (eregi('/$',$self)){$newurl = explode("/",$self);$newurl = $newurl[1];header("location:$newurl");}?>[/code] Quote Link to comment Share on other sites More sharing options...
mmosel Posted July 10, 2006 Author Share Posted July 10, 2006 Shogun, I think you are partly correct. It is probably looking for the page.php directory. But it's not returning a 404 error, but instead it's processing the script and outputting the html content, minus images and style. GingerRobot, I think you have a good idea, but it's not practical, because then anytime I had a slash in the url, it's going to redirect. Sometimes there might be a need for a trailing slash. I'll write up something custom to solve this I guess. I was just checking to find out if this is a common issue and if there was a common solution. Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted July 10, 2006 Share Posted July 10, 2006 That will only redirect if the forward slash is at the end of the file. Quote Link to comment Share on other sites More sharing options...
legohead6 Posted July 10, 2006 Share Posted July 10, 2006 its probably messing up where your style sheet is located or pics are located because you put the slash on the end? like i know sometimes when you go to a directory that has a index.htm in it it will automaticly go to that page! I.E www.example.com/main Quote Link to comment Share on other sites More sharing options...
ShogunWarrior Posted July 10, 2006 Share Posted July 10, 2006 GingerRobot had something going there, I tested this:[code]<?php$self = $_SERVER["PHP_SELF"];if (eregi('/$',$self)){$newurl = explode("/",$self);$newurl = $_SERVER['SCRIPT_NAME'];header("Location:$newurl");}?>[/code[When I used it like so: [b]http://www.domain.com/index.php/[/b] it will redirect to [b]http://www.domain.com/index.php[/b][/code] Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted July 10, 2006 Share Posted July 10, 2006 Just realised, that wouldn't work if the file was in a sub directory, but this would:[code]<?php$self = $_SERVER["PHP_SELF"];if (eregi('/$',$self)){$newurl = explode("/",$self);foreach($newurl as $newurl){ if(eregi('[[:alnum:]]\.[[:alnum:]]',$newurl)){ $url = $newurl; break;}}header("location:$url");}?>[/code] Quote Link to comment Share on other sites More sharing options...
mmosel Posted July 10, 2006 Author Share Posted July 10, 2006 [quote author=GingerRobot link=topic=100025.msg394748#msg394748 date=1152566474]That will only redirect if the forward slash is at the end of the file.[/quote]I realise that, but what if the url looks like:mydomain.com/category1/category2/I didn't test it, but my guess is that your code wouldn't work here.-----Note, I wrote this before Ginger's last post. I don't know how your new code would affect this. One solution might be to test the REQUEST_URI for a '.ext/' case and then if found, strip the slash, or just strip everything after the .ext if one doesn't plan on allowing that condition. Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted July 10, 2006 Share Posted July 10, 2006 [quote author=mmosel link=topic=100025.msg394775#msg394775 date=1152568146][quote author=GingerRobot link=topic=100025.msg394748#msg394748 date=1152566474]That will only redirect if the forward slash is at the end of the file.[/quote]well given that the code would have to be placed in a file, so the url would have to be something like mydomain.com/category1/category2/file.php /the updated code would work.I realise that, but what if the url looks like:mydomain.com/category1/category2/I didn't test it, but my guess is that your code wouldn't work here.[/quote] Quote Link to comment Share on other sites More sharing options...
ShogunWarrior Posted July 10, 2006 Share Posted July 10, 2006 Well I imagine that the 404 should kick in there, not a place for PHP. Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted July 10, 2006 Share Posted July 10, 2006 This is all does seem kind of pointless though, i mean, if someone wants to go fiddling with the url what do they expect? Quote Link to comment Share on other sites More sharing options...
mmosel Posted July 10, 2006 Author Share Posted July 10, 2006 [quote author=GingerRobot link=topic=100025.msg394782#msg394782 date=1152568752]This is all does seem kind of pointless though, i mean, if someone wants to go fiddling with the url what do they expect?[/quote]Well, perhaps you are right. But it bugs me and it just seems like a flaw. If it is fixable, then why not fix it? Quote Link to comment Share on other sites More sharing options...
mmosel Posted July 10, 2006 Author Share Posted July 10, 2006 Ok, here's my code! $uri = $_SERVER['REQUEST_URI'];[code]$slashcheck = "\.{1}[a-zA-Z]{3}/+";$extcheck = "\.{1}[a-zA-Z]{3}";if (eregi($slashcheck, $uri)){ //echo "slashfound<br />"; $newurl = '/'; $uri = explode('/', $uri); $count = count($uri); $x = 0; $end = 0; foreach($uri AS $value){ $x++; if(!eregi($extcheck, $value) && $value !='' && $end != 1){ $newurl .= $value.'/'; //echo $value." Has has no ext.<br />"; } if(eregi($extcheck, $value) && $end != 1){ //echo $value." Has an .ext<br />"; $newurl .= $value; $end = 1; } }//end foreach echo $newurl."<br />";}//then of course course redirect to new location...[/code]As an example, $uri = 'index1.php/index2/index3.php/';returns:index1.php$uri = 'index1php/index2/index3.php/';returns:index1php/index2/index3.php$uri = 'index1php/index2.php/////index3.php/';returns:index1php/index2.php Quote Link to comment Share on other sites More sharing options...
mmosel Posted July 11, 2006 Author Share Posted July 11, 2006 Another tip that I received on another board I visit is a very simple and elegant solution. It doesn't require any special code. Just use the base tag:<base href="http://mydomain.com/" />And then all of your relative links will magically work as if they were absolute links!Such a simple thing, but it works like a charm. Works for .css, images, and more. Quote Link to comment Share on other sites More sharing options...
ShogunWarrior Posted July 11, 2006 Share Posted July 11, 2006 Except in some browsers ;) Quote Link to comment Share on other sites More sharing options...
mmosel Posted July 13, 2006 Author Share Posted July 13, 2006 [quote author=ShogunWarrior link=topic=100025.msg395472#msg395472 date=1152660622]Except in some browsers ;)[/quote]Really? The base tag doesn't work in all browsers eh? Do you know which ones? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.