Jump to content

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


mmosel

Recommended Posts

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.
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.
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]
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 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 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 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?
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
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.

Archived

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

×
×
  • 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.