Title: htaccess direct all non-server side file requests to a specific subdirectory
Tags: php;mod-rewrite
Question: I'm developing a templating-based CMS with the following structure:
/public_html/admin/
^ contains all CMS files and functions, etc.
/public_html/user_html/
^ is the directory the client accesses with FTP and manages all client side files (i.e. html, javascript, css, jpg, png, etc.) but is disallowed privileges to add server-side files (i.e php etc).
/public_html/index.php
^ is the root public directory which drives the site/application itself, index.php is the only file in this directory and it processes URI requests and runs the application.
A little further on the system and structure: it is set up so that all html files within user_html act as templates/layouts for certain modules of the system - these files have custom tags to output the system functions and the server reads all files and folders from user_html when requested and outputs them to the application.
This is all fine and runs a treat. What I am trying to achieve here is to hide the user_html for all URL browser requests. So basically all paths within the html pages currently have to be read like so to work:
src="/user_html/js/scripts.js",
src="/user_html/css/styles.css"
src="/user_html/images/logo.png"
whereas the desired paths for the user/client to input when creating and editing the html pages would be as follows:
src="/js/scripts.js"
src="/css/styles.css"
src="/images/logo.png"
The client has full control over the directories and files within the user_html directory, so therefore all file paths will be forever changing. Basically the browser needs to know all files and the directories in which these files are found reside within user_html, however be displayed as if they reside in public_html.
If anybody has a simple answer using htaccess to route all URI requests, except for .php files and the /admin/ directory to user_html, or any other thoughts and ideas, that would be greatly appreciated.
I've searched far and wide but cannot find a solution for what I'm after. However I'm sure it's going to be quite a simple RewriteCondition &amp; RewriteRule.


Here is another answer: Yes, it's just some rewrite rules!
If you can accept URLs of the form "js/foo.js", then you just need an .htaccess file in public_html.
# everything that's not .php or in /admin goes to user_html.
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !^(.+)\.php$
RewriteCond %{REQUEST_FILENAME} !^/admin(.+)$
RewriteRule ^(.+)$ /user_html/$1 [NC]
Comment for this answer: Thought so that's perfect!
Comment for this answer: Only thing is the paths don't work/aren't found when the first Condition is used **"RewriteCond %{REQUEST_FILENAME} !^(.+)\.php$"** it returns a "500 internal server error". It's fine with **"RewriteCond %{REQUEST_FILENAME} !-f"**. I haven't had time to test further but I will shortly. Thanks for your prompt answer!

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2012:00:12/10/12', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<php><mod-rewrite>', 'Title': 'htaccess direct all non-server side file requests to a specific subdirectory', 'ViewCount': 304, 'id': 13793358, 'user_AboutMe': '', 'user_AccountId': 1440146.0, 'user_DisplayName': 'J Charles', 'user_Reputation': 390.0, 'user_Views': 11.0, 'user_id': 1360528.0}}