February 29, 2012

htaccess for own php mvc framework

Question by paganotti

Good Morning,
I’m building my own php framework. I would want that all request pass to index.php file except request to js css jpeg, jpg, png file. So I want that a module independently to others has own assets folder with css images and js file.

The Structure is something similar:

application
   module1
     models
     controllers
     templates
         assets
             css
             images
               test.jpg
               hello.png
             js

         view1.html.php
         view2.html.php

   module2
     models
     controllers
     templates
         assets
             css
             images
               test.jpg
               hello.png
             js

         view1.html.php
         view2.html.php
  core
    here is core file framework

  index.php

How Can I do it?

Update

My modules are under application folder. assets folder must be public.
I want a simple small url like www.example.com/module1/images/test.jpg

instead long

www.example.com/application/module1/templates/assets/images/test.jpg

Answer by Starx

Actually, the default .htaccess of zf works well for this

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!