I'm trying to support themes in our app.
The designers create designs using the usual suspects of html, css, js and resources like images.
The themes are packaged as directories which can be tested standalone in a web browser for example:
http://example.com/dir1/dir2/..../dirX/themeZ/index.html
The entry point for the app (and other controller files) is on a different URL for example:
http://example.com/dir1/dir2/..../dirX/dirY/app.php
Now, app.php knows where themeZ/index.html is located and loads the html file and outputs the content. The problem is that all 'design' related files like css, js, images etc. are not found because the paths are relative.
My solution is to create a .htaccess file and have a rule that says all requests that don't end in '.php' to route them to the themeZ path.
I'm a beginner with htaccess rewriting. I've got as far as:
开发者_开发知识库RewriteRule \.css$ ../themeZ/style.css
RewriteRule \.js$ ../themeZ/functions.js
RewriteRule \.jpg$ ../themeZ/1.jpg
[etc]
but of course this needs major updating. It's not very dynamic, when themes are switched the htaccess files needs updating - not good. Also, resource files can be in different sub folders.
Can anyone give some guidance? Is this the best way to handle themes in an app?
RewriteRule .*?/(.+?\.(css|js|jpg))$ /dir1/dir2/dirX/themeZ/$1 [NC,last]
精彩评论