.htaccess - Redirect all to index.php htaccess -


my apologies 10000000th question on topic, can't work way want it.

i'm writing simple php mvc'ish framework. want framework able installed in directory.

what php script : grabs request uri , breaks off segments. making segment 1 controller , segment 2 action. goes fine when this:

http://www.domain.com/mvc/module/test/

it go specific module controller , method. have default controller, home controller, in folder home.

now when acces folder directly http://www.domain.com/mvc/home/ display 403 forbidden, because folder exist, instead should go http://www.domain.com/mvc/index.php

if have installed framework in different folder, lets folder framework has redirect http://www.domain.com/framework/index.php

i redirect every folder , php file index.php, leaving else way is.

my first problem encountered never redirects right folder, domain root folder.

this tried :

rewriteengine on rewritecond %{request_filename} !-d rewritecond %{request_filename} !-f rewriterule . index.php [l] 

i hope me out or point me right direction!

thanks alot!!

your rewrite rule looks ok.

first make sure .htaccess file in document root (the same place index.php) or it'll affect sub-folder it's in (and sub-folders within - recursively).

next make slight change rule looks like:

rewriteengine on rewritecond %{request_filename} !-f rewritecond %{request_filename} !-d rewriterule ^(.*)$ /index.php?path=$1 [nc,l,qsa] 

at moment you're matching on . one instance of character, need @ least .* match number of instances of character.

if want whole shebang installed in sub-directory, such /mvc/ or /framework/ least complicated way change rewrite rule take account.

rewriterule ^(.*)$ /mvc/index.php?path=$1 [nc,l,qsa] 

and ensure index.php in folder whilst .htaccess file in document root.


the $path variable contain fake directory structure, /mvc/module/test instance, can use in index.php determine controller , actions want perform.

the flags:

nc = no case (not case sensitive, not necessary since there no characters in pattern)

l = last (it'll stop rewriting @ after rewrite make sure it's last thing in list of rewrites)

qsa = query string apend, in case you've got ?like=penguins on end want keep , pass index.php.


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -