简体   繁体   中英

htaccess direct all non-server side file requests to a specific subdirectory

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 (ie html, javascript, css, jpg, png, etc.) but is disallowed privileges to add server-side files (ie 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 & RewriteRule.

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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM