I’ve looked at many examples here and all over the internet, but I can’t seem to find an answer I understand, or that accurately solves my problem. I’m looking to implement a mod_rewrite directive in an .htaccess file that renames a folder to another name but does not show the name in the url bar.
For example (the user clicks a link that directs them to):
theSite.com/folder1/folder2/folder3/
I want them to see (same as above)
theSite.com/folder1/folder2/folder3/
But I want the browser to silently function in this directory
theSite.com/folder1/some_other_folder/folder3/
I am a PHP developer, writing my first web application. I can configure apache, PHP, mysql and use them like a pro. I’m sorry, but I don’t understand the syntax for mod_rewrite. I can’t seem to grasp it despite looking at many tutorials as I would need to ask questions before I could move onto the next concept. Thank you for your patience.
Your case is pretty run-of-the-mill. You just need to match the static string, plus a
(.*)to match everything that follows it and store it into$1, then substituesome_other_folder.The
[L]flag (and absence of the[R]flag) instructs Apache to rewrite internally without redirecting the browser, and to stop here without matching further rules.If
folder3itself is part of the “dynamic” portion, that is, anything afterfolder2should be silently rewritten intosome_other_folder, leavefolder3out of the rule and just capture everything that followsfolder2into$1.