Page 1 of 1

Learning MVC .. need to understand htaccess.

Posted: Thu Nov 20, 2014 3:55 am
by gautamz07
Hey guys i have a questiion about the htaccess file and it is specific to a little demo project that i am doing ,

have a look below , i have the following directory structure :

App
- htaccess file
- controllers
- home
- core
- app
- controller
- modals
- Users
- views
- index.php
- home
- init.php

Public
- CSS
- index.php
- htaccess file


now inside the htaccess file in public , i have the following commands :

Code: Select all

Options -MultiViews
ReWriteEngine On

RewriteBase /mvc_model/public


RewriteCond %{REQUEST_FILENAME}  !-d
RewriteCond %{REQUEST_FILENAME}  !-f


RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]

:banghead: :banghead:

can somebody thoroughly explain to me what the above commands are doing ? ld please don't re direct me to another URL , i would prefer a human explanation .

i appreciate your time and patience .

gautam.

Re: Learning MVC .. need to understand htaccess.

Posted: Thu Nov 20, 2014 6:26 am
by Celauran
mvc_model, I'm assuming, is your app's parent directory (i.e. App and Public above are both subdirectories of mvc_model). The RewriteBase directive is saying that all rewrite rules should be relative to that directory.

Code: Select all

RewriteCond %{REQUEST_FILENAME}  !-d
If the file requested isn't a directory

Code: Select all

RewriteCond %{REQUEST_FILENAME}  !-f
And the filename isn't a file

Then apply the following rewrite rule

Code: Select all

RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
This rule says to start at the beginning of the URI (^), capture any character (.) any number of times (+) until the end of the URI ($), and pass that as a query string to index.php. Do not process any other rewrite rules (L), and include any query string that was on the original URI (QSA).

index.php probably loads your autoloader, does some basic bootstrapping, and then dispatches the request as per your routing rules.