How can I rewrite this url
localhost/store/admin/employee/position/cashier.php?name=John
to
localhost/store/John
without having to move the files
I don’t even know if it is possible? Please I need help. And if it is possible, where should the .htaccess located at? Should it be in the store directory?
2
Answers
It certainly is possible to rewrite such request just as you suggest. I doubt however that this is what you will settle with later. Because the connection from a store to a cashier is surprising …
However, to give you a starting point, in addition to all the available tutorials you can easily find online, this might help:
This assumes you are using the apache http server, which is likely since you explicitly ask for a ".htaccess" file. Obviously the rewriting module that defines these directives needs to be loaded into the http server.
You can implement such a rule in the http server’s virtual host configuration. If you plan to deploy your solution to a service where you do not have control over that (read: a cheap hosting provider), then you can instead use a distributed configuration file (typically called ".htaccess". Such file should be located in the folder defined as
DOCUMENT_ROOT
in the http host configuration (so typically something like/var/www/default
or similar, check your configuration), so that folder wherehttp://localhost
currently points to. The file has to be readable for the http server process. And you need to enable the interpretation of such directives by means of theAllowOverride
directive in your central http server’s configuration.It is important that you take the time to actually understand that implementation. Do not simply copy something you find here blindly, you will not learn anything that way. A good starting point to understand the details like directive, pattern, flags is the documentation of the tools you want to use, so here the rewriting module available for the apache http server. As typical for OpenSource software it is of excellent quality and comes with great examples: https://httpd.apache.org/docs/current/mod/mod_rewrite.html
If the /store (http://localhost/store) is you base URL then you can try with below
.htacces file