I have been trying to do this with .htaccess
, but not having any luck.
I have a tree folder structure for users, where there are 3 levels of "a-z" followed by the user name, so for my user "john", on the server the folder would be in…
example.com/users/j/o/h/john
But I want to be able to serve this folder with the URL example.com/john
Is this possible with .htaccess
or some other Apache method?
2
Answers
If you have to do this redirect all traffic to your index.php file. Then you can match the full url in your index.php file with the one you want so that it includes the page you want. There are some php resources that can do this. I’ve seen projects with results using a similar structure on codeinteger.
You will have to capture each of the first three letters on its own, and then assemble the matches in the right sequence:
This is assuming that your usernames can consist of lower-case letters only. If you need to take into account more characters, then you will need to modify the used character classes accordingly.