Jump to content

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


mmosel

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?
Link to comment
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.
Link to comment
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.
Link to comment
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
Link to comment
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]
Link to comment
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]
Link to comment
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.
Link to comment
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]
Link to comment
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?
Link to comment
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
Link to comment
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.