Apache mod_rewrite : How to REWRITE (or whatever) child directories to parent?

Posted by ???? on Stack Overflow See other posts from Stack Overflow or by ????
Published on 2013-10-24T10:51:24Z Indexed on 2013/10/26 9:54 UTC
Read the original article Hit count: 135

Filed under:
|
|
|

Actually i am trying to make a PHP MVC like application. A basic one. The current milestone i am reaching already includes:

  • Basic RESTful Routing

Means, if i type:

  • www.example.com/items/book/8888

.. it properly just stays there as it is and i can already slice out the URL by slashes / and loads the responsible Controllers .... etc from the top single index.php file. I mean, so it is OK for the backend PHP.

But the only problem is, it still CAN NOT process the REWRITES properly. For example, the CSS & JS are BROKEN as if i VIEW PAGE SOURCE of the page www.example.com/items/book/8888, the asset files are being called as:

  • www.example.com/items/book/8888/css/main.css
  • www.example.com/items/book/8888/js/jquery.js

.. which really are PROBLEMS because in the code is like:

  • <link type="text/css" rel="stylesheet" media="all" href="css/main.css">
  • <script type="text/javascript" src="js/jquery.js"></script>

So the question is:

  • How can i use Apache REWRITE (or whatever approach) to make sure every ASSET FILES to be correctly being called from the DOCROOT.

For example, if i am in the URL:

  • www.example.com/items/book/8888

My ASSET FILES should still be called as:

  • www.example.com/css/main.css
  • www.example.com/js/jquery.js

Or is there any other methods i need to follow? Please kindly help suggest. Thank you.

© Stack Overflow or respective owner

Related posts about php

Related posts about apache