#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    407
    Rep Power
    8

    Index.php in a directory


    hi,

    I've got this setup as directory:

    -root
    --includes
    --some files
    --index.php 1)
    --messages
    ---index.php 2)
    etc.

    So it all works like it should, if you only enter www.domain.com you get index.php 1) and when you enter www.domain.com/messages you get index.php 2).

    But now my problem, when I type something like www.domain.com/messages/unknown_file.php I get index.php 1), but without css. Where could the problem be and is it solvable with php, like using the "define" function or something?
  2. #2
  3. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,957
    Rep Power
    1046
    Hi,

    the configuration of your webserver is broken. Missing files are supposed to trigger a 404 error, not redirect to some other file.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    407
    Rep Power
    8
    ok, I always thought when you just type in something after the domain (www.domain.com/something) that you would be redirected to the index.php (or index.html etc.)
  6. #4
  7. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,957
    Rep Power
    1046
    Not really. You can do that (obviously), but it's just stupid. Imagine the user makes just a small typo somewhere in a long URL, or they use an obsolete URL. Then the server would throw away the whole URL and instead redirect to a completely different default page, leaving the user clueless about WTF just happened.

    Show a 404 page and let the user decide what to do next.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  8. #5
  9. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    407
    Rep Power
    8
    ok thanks, again
  10. #6
  11. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,317
    Rep Power
    7170
    Most PHP frameworks will route all requests for non-existent files to index.php using mod_rewrite (assuming you're using Apache). In that case, it's the responsibility of the framework rather than the web server to generate a 404 page when appropriate.

    The fact that your CSS appears broken suggests to me that you are not actually being redirected, and that your index.php is using a relative path to its CSS file which does not load when you visit unknown_file.php because the URL is not relative to the root.

    mod_rewrite can either do an actual redirect, in which case the URL would have changed to /index.php, or it can simple reroute the request to a different file, in which case the URL would still show unknown_file.php.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  12. #7
  13. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    407
    Rep Power
    8
    ok thanks, I'll try to get this done...
  14. #8
  15. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,957
    Rep Power
    1046
    Originally Posted by derplumo
    ok thanks, I'll try to get this done...
    Um, do you even have a framework like CakePHP or Symfony? All code I've seen from you was plain PHP with no framework whatsoever.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  16. #9
  17. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    407
    Rep Power
    8
    I don't think I have hahaha
  18. #10
  19. No Profile Picture
    Dazed&Confused
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2002
    Location
    Tempe, AZ
    Posts
    506
    Rep Power
    128
    He might not have a full framework but it sounds like he has the .htaccess file of one.

    That or his webhost puts some really idiotic default behaviors into the vhost conf file.
  20. #11
  21. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    407
    Rep Power
    8
    well, I'm now going to take a look at htaccess...
    Last edited by derplumo; July 8th, 2013 at 10:25 AM.
  22. #12
  23. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    407
    Rep Power
    8
    ok, there is only something in it refering to an other subdomain... ok I don't know what to do now...
  24. #13
  25. No Profile Picture
    Dazed&Confused
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2002
    Location
    Tempe, AZ
    Posts
    506
    Rep Power
    128
    Originally Posted by derplumo
    ok, there is only something in it refering to an other subdomain... ok I don't know what to do now...
    If you don't see any rewriting being done in your .htaccess file then it must be at a lower level, in the vhost config file. If you don't maintain the server yourself, you might have to contact whoever does.
  26. #14
  27. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2004
    Posts
    2,971
    Rep Power
    375
    you could always paste the contents of htaccess here?
  28. #15
  29. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    407
    Rep Power
    8
    Originally Posted by paulh1983
    you could always paste the contents of htaccess here?
    Well the contents are for an other subdomain, so it doesn't apply for this one...

IMN logo majestic logo threadwatch logo seochat tools logo