Do I have to generate all directories in URL


Reaction score
I couldn't find information about this anywhere.
I have a website where people can make something and save it into a short url.
Do I have to actually make a new directory and an index.php file for every version? It seems so unnecessary.
I have noticed that there is no index.php file at for example.
Do I have to do something with the htcaccess file?

I would be glad if someone could help me solving this


Well-Known Member
Reaction score
No and yes.
You don't create directories, you instead use a GET request to fetch the data.
For .htaccess, you have to make it work with a clean URL. Something like this should do the trick:
RewriteEngine On
Options +FollowSymLinks
Options -Multiviews
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)$ /?fileid=$1 [L]
You may need to modify the code for it to work here correctly, so that a 500 internal server error doesn't appear.
As you can see, the GET request used in that .htaccess code is 'fileid'. You may want to use something else, your preference.
You can actually set up a redirect if the actual GET request is present in the URL bar (not clean). The dirty way (GET request present in bar) is still usable so I would advise you to do that.

Of course, if you want to have some main page if nothing is present on the top bar after the URL (apart from the forwardslash), trim the GET request and do an IF statement checking if there's no input (identified as '' [those are single quotes, nothing between them, meaning that it's literally nothing]) as or if there's a singular blank space (trim will cut down multiple white spaces into one). If you want it to redirect to a page with an ID (when you visit the main page) like, well, you know what to do from there, just don't forget to check if an unused file ID (not real file) is blank or just a whitespace (same method for the GET request as mentioned before for my main page example), just to save space.

Fun fact: You can use different GET requests even if this clean URL thing is in place.

Just something important I almost forgot to mention. If you add '/' at the end of the file ID or whatever you would want to call it, it'll be detected as a directory, so avoid the forwardslash unless you're intending to go into a directory.

The secret of finding things like this is to search or create one part of each until it fully builds up, don't go with the big chunck or it'll make it harder.
Last edited: