0

This is how it looks without the '/' (localhost/index.php): http://postimg.org/image/jxg239qzn/

After adding it at the end of url (localhost/index.php/): http://postimg.org/image/e01pe0isv/

Anyone with experience that could just give a short tip about a probable reason of that.

Here is the index.php :

require_once("php/config.php");
if(substr_count($_SERVER['PHP_SELF'],'/')==1){ // fixing that bug  
    require_once( ROOT_PATH . "php/header.php" );   
    if(isvalid(quizzid()) == true){
        switch(quizzid()){
            case 0:
                require_once( ROOT_PATH . "php/questionarios.php" );
                break;
            default:
                require_once( ROOT_PATH . "php/questionario.php" ); 
                break;
         } 
     }          
     require_once(ROOT_PATH . "php/footer.php");    // footer
}else{ // if there are more than 1 '/' it would redirect to > index
    header('Location: /index.php');
}
Vladimir
  • 5
  • 4
  • Please show us your code from `index.php`. – Rizier123 Feb 06 '15 at 09:25
  • You are most likely using relative paths for your CSS files. Change to absolute paths or set a base – Spokey Feb 06 '15 at 09:37
  • Ok , I posted the code, sorry about the delay, anyways I'll investigate about path types and how to manage it, that's exactly what I needed. Thanks about your worry. – Vladimir Feb 06 '15 at 09:39

4 Answers4

1

Screenshots shows that your site doesn't load the external files (CSS, JS, images) when you append a trailing slash at the end of the URL.

The most probable cause to this is because you use relative paths for your external files.

<link rel="stylesheet" type="text/css" href="style.css">

Your browser will try to load http://localhost/index.php/style.css instead of http://localhost/style.css.


Using an absolute path for your external files will correct the problem.

<link rel="stylesheet" type="text/css" href="/style.css">

You can also use the <base> element in HTML, which will configure all relative paths to be fetched from a specific directory: this will affect all CSS / JS / image files, so it's a faster solution than changing all relative paths to absolute.

<base href="http://localhost/">

I would also suggest setting the AcceptPathInfo to Off in Apache's configuration. This will make requests to http://localhost/index.php/ to get a 404 Not Found response.

Benoit Esnard
  • 2,017
  • 2
  • 24
  • 32
0

I would guess that the server is assuming that "index.php" is a directory and looking for an index file with the path "localhost/index.php/index.php". Have you tested to see if this is potentially the issue?

C-Dawg
  • 61
  • 3
  • I had a directory called 'php', just renamed to include but the problem still, at this moment I'm googling about relative/absolute paths, that might be the problem. I appreciate your attention and I'll post the problem when it get fixed. – Vladimir Feb 06 '15 at 09:47
  • You was right, I used absolute path to fix it. – Vladimir Feb 06 '15 at 12:17
0

After adding /, the include path changes from localhost to localhost/index.php/ and search for config.php at location localhost/index.php/php/config.php which does not exists.

Therefore your ROOT_PATH is not getting set after adding /.

Use absolute path ( full path ) while including config

require_once("/php/config.php");

RajeshK
  • 459
  • 5
  • 10
0

I just realized where is the problem, shame on me about the stupidity of that bug.

Everywhere where I used to include a img, css, js or anything else, I used by this way:

(before) link rel="stylesheet" type="text/css" href="css/css.css"

(after) link rel="stylesheet" type="text/css" href="/css/css.css"

Here is a well answered question about this: relative path to CSS file

Thank you and sorry if annoyed with my stupidity.

(I would like to put a +1 on every answer, but I need 15 of reputation.)

Community
  • 1
  • 1
Vladimir
  • 5
  • 4