.htaccess - rewriting url requests and taking care of resource files
I thought i should open a new question for a matter related to my previous one (you can find it here). The situation is very similar to that question, but i found a different approach, and would like to know if it's correct.
I wanted to rewrite the urls for my site, and being able to take care of resource files (css, js, images, etc) so that browser doenn't search for them in the wrong directory.
Following are snippets of the html code of a sample page found browsing for example to articles/writer/erenor (here htaccess rewrites the url to /articles.php?writer=erenor, and this part works well).
Into <head> tag:
Into <body> tag:
<img alt="Avatar" src="./inc-images-files/avatar.png"> <img alt="Pattern" src="./inc-images-files/pattern/violet.png"> <br><br> <a href="/articles/writer/erenor">Writer Erenor</a>
Now, i have this snippet from .htaccess file:
And, finally, the example of the file structure:
I just tested the code, and it seems to work: my browser asks for the css file (searching it in the "wrong" place) and it retrieves it correctly, so i'm quite happy with it :) Links in the page will be like the one in the html shown above, which seems to work well.
Questions: 1. Is this a good approach to be able to avoid browsers requests to resources being in the "wrong" place? (I know that i will have to add more parameters when it comes to other files like for example videos, txt's, tga, etc etc etc) 2. Should i move this site to production server, will it work without modifications? In other words, is this a kind of "box" that can be moved here and there easily?
A little note: since these are just code snippets, tell me if something appears to be missing..maybe i just forgot to copy/paste it ;-)
You seem to be requesting the files in the current directory. Why do you do that? Why don't you request the from the site root? (remove the '.'). If I read it correctly, on /articles/writer/asdf and /articles/writer/zxcv the files will request /articles/writer/asdf/inc-css-files/index.css and /articles/writer/zxcv/inc-css-files/index.css. The browser sees this as two different files. If the user requests 100 writers, it will download index.css 100 times, and caches the same file 100 times under different names. That is wasteful.
I recommend requesting the files relative to the site root instead if you have the files stored in a folder in the site root.