Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Feb 2007
    Posts
    113
    Thanks
    6
    Thanked 1 Time in 1 Post

    Handling subfolders that don't exist

    Let's say I have a folder at the root of my site like this:

    http://example.com/folder1

    Note: there are no subfolders in this folder.

    Now if a person typed in http://example.com/folder1/subfolder

    normally, this would show a 404 error page. How can I handle this with a PHP script located in folder1, without using mod-rewrite.

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    How do you want to handle it? Redirect? Display custom not found page? or..?

  • #3
    Regular Coder
    Join Date
    Feb 2007
    Posts
    113
    Thanks
    6
    Thanked 1 Time in 1 Post
    Yes either one will do. What is important is, I don't want to deal with config files, htaccess, etc. Just PHP.

  • #4
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    I doubt you can do this with PHP. It's not the job of PHP.

  • #5
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,517
    Thanks
    114
    Thanked 110 Times in 109 Posts
    I don't think so either. How can you expect any script to do anything when it wasn't executed in the first place. It is the job of apache (or the web server) to decide which script is run in relation to what is in the url request. Just out of curiosity why do you want to avoid htaccess or ht configuration. Is it because your host doesn't support it? If not i really wouldn't fear it. It's fairly straight forward.
    You can not say you know how to do something, until you can teach it to someone else.

  • #6
    GŁtkodierer
    Join Date
    Apr 2009
    Posts
    2,127
    Thanks
    1
    Thanked 426 Times in 424 Posts
    The PHP solution for this is quite straightforward. You just need a loop that generates all possible folder names.

    Within this loop, create those folders on the server and into each one of them copy a php file that includes another php file in its parent directory, which should contain the routine handling the output in case the user navigated to a subfolder.

    It's probably running a few days, so you will have to change the time limit in php.ini. Or was php.ini one of the things you didn't want to have anything to do with? Then I'm sorry I couldn't help.

    I'm kidding of course.

  • #7
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,517
    Thanks
    114
    Thanked 110 Times in 109 Posts
    Quote Originally Posted by venegal View Post
    The PHP solution for this is quite straightforward. You just need a loop that generates all possible folder names.

    Within this loop, create those folders on the server and into each one of them copy a php file that includes another php file in its parent directory, which should contain the routine handling the output in case the user navigated to a subfolder.

    It's probably running a few days, so you will have to change the time limit in php.ini. Or was php.ini one of the things you didn't want to have anything to do with? Then I'm sorry I couldn't help.

    I'm kidding of course.
    Hehe funny solution Although would run for infinity and require infinite hard disk space. I wonder does setting the php ini setting to 0 allow it to run for infinity?
    You can not say you know how to do something, until you can teach it to someone else.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •