php - Htaccess rewrite rules for this url -


i started learn htaccess , i'd rewrite current urls this:

http://www.url.com/?location=script 

to:

http://www.url.com/script 

so far i've managed want have directory more controllers can have this:

http://www.url.com/script/method 

structure: script directory --> method.php

currently directory structure includes this:

assets-->client(directory):

  • login.php
  • logout.php
  • register.php
  • something.php

and i'd access these using url like:

    url.com/client/login     url.com/client/logout     url.com/client/register     url.com/client/something 

my .htaccess:

    <ifmodule mod_rewrite.c> rewriteengine on rewritecond %{request_filename} !-f rewritecond %{request_filename} !-d rewriterule ^([^/]+)/?$ index.php?location=$1 [l] </ifmodule> 

php based inclusion code:

#################################################################### #                       parse current page                     # ####################################################################    $includedir =".".directory_separator."assets/controllers".directory_separator;   $includedefault = $includedir."home.php";      if(isset($_get['ajaxpage']) && !empty($_get['ajaxpage'])){         $_get['ajaxpage'] = str_replace("\0", '', $_get['ajaxpage']);         $includefile =   basename(realpath($includedir.$_get['ajaxpage'].".php"));         $includepath = $includedir.$includefile;         if(!empty($includefile) && file_exists($includepath)) {             include($includepath);         }         else{             include($includedefault);         }         exit();     }     if(isset($_get['location']) && !empty($_get['location']))             {                 $_get['location'] = str_replace("\0", '', $_get['location']);                 $includefile = basename(realpath($includedir.$_get['location'].".php"));                 $includepath = $includedir.$includefile;                  if(!empty($includefile) && file_exists($includepath))                  {                     include($includepath);                 }                 else                  {                     include($includedefault);                 }              }              else              {                 include($includedefault);             } 

all controllers in assets/controllers/ucp/login.php example.

how about:

<ifmodule mod_rewrite.c>     rewriteengine on     rewritecond %{request_filename} !-f     rewritecond %{request_uri} ^(/client/[a-za-z0-9_\-]+)$     rewriterule ^[a-z]+ index.php?location=$2 [l] </ifmodule> 

it include leading slash , doesn't have php extension. can altered in php suit needs.

be wary though, code gives access php files. might want check $_get['location'] against array of allowed locations. consider following url example of how go wrong

http://example.com/index.php?location=../drop_database.php 

Comments

Popular posts from this blog

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

javascript - Blogger related post gadget image Resize s72-c [ Need Expert Help ] -