...

View Full Version : Handling subfolders that don't exist



eapro
05-11-2009, 06:43 PM
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.

Fumigator
05-11-2009, 08:17 PM
How do you want to handle it? Redirect? Display custom not found page? or..?

eapro
05-11-2009, 08:55 PM
Yes either one will do. What is important is, I don't want to deal with config files, htaccess, etc. Just PHP.

Fumigator
05-11-2009, 10:26 PM
I doubt you can do this with PHP. It's not the job of PHP.

timgolding
05-11-2009, 10:42 PM
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.

venegal
05-11-2009, 11:05 PM
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.

timgolding
05-11-2009, 11:12 PM
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 :D 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?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum