you are looking for the .htaccess
file !
the .htaccess
is a simple file placed in the root directory and allows you to play with the directories and redirect any request to a specific file.
so for example, you can redirect any request for example.com/user/add
to example.com/index.php?e=user&a=add
and the user will only type and see example.com/user/add
in the address bar. but the actual file that is displayed is example.com/index.php?e=user&a=add
I will take you through the steps needed to achieve that:
- in order to display
example.com/user/add
instead of
example.com/index.php?e=user&a=add
first you will need to create a
hidden file which starts with a period and then htaccess
and that file should be placed in the main directory
- then open that file and write into it the following:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^user/add index.php?e=user&a=add [NC]
Note:
but that will redirect the exact same url example.com/user/add
. if you wanted the user
to be a variable so it could be anything such as example.com/hello/add
you will need to change your .htaccess
content to this:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/add index.php?e=$1&a=add [NC,L]
so know {user} is a variable and will be redirected to index.php?e={user}&a=add