Do I have to generate all directories in URL

gaptrast

Member
Messages
123
Reaction score
0
Points
16
Hi,
I couldn't find information about this anywhere.
I have a website where people can make something and save it into a short url.
example.com/s08qt/
example.com/lfliy/
example.com/mkd30/
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 bit.ly for example. https://bitly.com/BdRHD/index.php
Do I have to do something with the htcaccess file?

I would be glad if someone could help me solving this
 

caftpx10

Well-Known Member
Messages
1,534
Reaction score
114
Points
63
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:
Code:
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 notepad.cc, 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:
Top