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...
mysite.com/users/j/o/h/john
But I want to be able to serve this folder with the url mysite.com/john
Is this possible with htacces or some other apache method?
CodePudding user response:
You will have to capture each of the first three letters on its own, and then assemble the matches in the right sequence:
RewriteRule ^users/([a-z])([a-z])([a-z])([a-z] )$ /users/$1/$2/$3/$1$2$3$4
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.
CodePudding user response:
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.