Jump to content

Archived

This topic is now archived and is closed to further replies.

mmosel

Quirk when adding a slash '/' after page.php

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Show more code why are you applying a slash to the end index.php/

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
seems a little pointless, but:

[code]
<?php
$self = $_SERVER["PHP_SELF"];
if (eregi('/$',$self)){
$newurl = explode("/",$self);
$newurl = $newurl[1];
header("location:$newurl");
}
?>
[/code]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
[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.

Share this post


Link to post
Share on other sites
[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]

Share this post


Link to post
Share on other sites
This is all does seem kind of pointless though, i mean, if someone wants to go fiddling with the url what do they expect?

Share this post


Link to post
Share on other sites
[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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
[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?

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.