Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using index.php with includes & folders instead of named php files

Say I have a user database and don't want to use get to get the id (user.php?i=234) and want to use folders and index.php(s) instead (user/234)

I can do this by creating a new folder and index.php file in that folder when the user registers. I can put an include inside the index.php file (include '/users.php') and call a function that builds the page (buildUserPage(234);)

Is this the best way to do this?

How can I get the user id based on the parent folder if 234 is the user id?

How can I check if the url of the page is index.php so I can redirect to "../"?

like image 671
Max Hudson Avatar asked Nov 23 '25 06:11

Max Hudson


1 Answers

In the .htaccess file in the user directory, place the following:

RewriteEngine On
RewriteRule ^(\d+)/?$ ../users.php?i=$1 [QSA,L]

For your question directory .htaccess file, try this:

RewriteEngine On
RewriteRule ^(\w+)?/?(\d+)?/?$ ../question.php?l=$1&i=$2 [QSA,L]
like image 150
ghbarratt Avatar answered Nov 24 '25 22:11

ghbarratt