I can see where the close voters are perhaps coming from*1, although it would arguably be "Needs details or clarity", rather than "Needs more focus" (the final "reason" given is not necessarily unanimous).
I did not cast a close vote myself but attempted to seek clarification at the time in comments below the question, but my questions went unanswered. (My questions could have been better, but it was a start.) Had I returned to the question later then a close vote would have been warranted, but there was no further activity on the question (or answers) until now(!?) so I did not get notified.
You've also not given any code sample(s), either what you have tried (not necessarily a close reason in itself IMO, although many would think so) or the contents of your existing .htaccess
file, which is arguably more important to reach a solution. (Conflicts with existing directives are a common cause of error.)
Whilst on the face of it, your question looks like a relatively "simple" rewrite, you've not actually stated what the intended target/response is, which makes this impossible to answer succinctly. The devil is in the detail.
@CBroe's answer does exactly what you are asking (the regex is spot on), but this is also why it cannot work*2. It is not "accepted", so I assume it doesn't, but why have you not tried to troubleshoot this in comments?
What is /users/j/o/h/john
? "on the server the folder would be in..." ("in" or "at"?) would seem to imply it is a filesystem directory (although I'm not entirely convinced). However, if it is a directory then the target MUST end in a trailing slash, but you have omitted the trailing slash throughout the question. (If you omit the trailing slash then mod_dir will trigger an external redirect to append the trailing slash and the underlying filesystem directory is exposed.) But if it is a directory, what are you expecting to be served? Apache does not serve directories, it serves files. Perhaps the intention is to serve the DirectoryIndex
document from that directory? But if that's the case then you should be rewriting directly to the document and cut out the middle man (mod_dir).
I asked in comments, "Are you intending to access files from this subdirectory?". If you are then you will likely need a different rewrite to handle this (or risk exposing the filesystem directory). But if not then why is it a directory and not a simple file (eg. john.html
)?
If /users/j/o/h/john
is not a physical directory (ie. /users/j/o/h/
is the directory and john
is some resource that needs to be served or passed to a front-controller), then this is not going to work. (But you make reference to a front-controller in comments on the other answer?)
*1 Although whether they are really voting for the reasons I've outlined here is another matter.
*2 Although it is missing the L
(or END
) flag so could also result in a conflict with later directives.