Custom routing in Zend Framework 1 -


i try configure additional route in zend framework 1 following.

$route = new zend_controller_router_route (     'test/route/',     array(         'module' => 'storefront',         'controller' => 'index',         'action' => 'index'      ) );  $router->addroute('customroute', $route); 

then try test route , enter following url in browser:

http://localhost:8888/selfstudy/zend/storefront/public/storefront/test/route/ 

i error page saying:" 404 not found. not found. requested url /index.php not found on server."

my application.ini gets loaded during bootstrapping process looks like:

[bootstrap] autoloadernamespaces[] = "zend_" autoloadernamespaces[] = "sf_"  phpsettings.display_errors = 0 phpsettings.error_reporting = 8191 phpsettings.date.timezone = "europe/london"  bootstrap.path = application_path"/bootstrap/bootstrap.php"  resources.frontcontroller.moduledirectory = application_path"/modules" resources.frontcontroller.defaultmodule = "storefront" resources.frontcontroller.params.prefixdefaultmodule = true resources.frontcontroller.throwerrors = false  resources.view = ""  resources.layout.layoutpath = application_path "/layouts/scripts" resources.layout.layout = "main"  [production : bootstrap]  [development : bootstrap] phpsettings.display_errors = 1 resources.frontcontroller.throwerrors = true  [test : bootstrap] 

for debugging dumped routes:

array (size=2)   'default' =>      object(zend_controller_router_route_module)[46]       protected '_defaults' =>          array (size=3)           'controller' => string 'index' (length=5)           'action' => string 'index' (length=5)           'module' => string 'storefront' (length=10)       protected '_values' =>          array (size=0)           empty       protected '_modulevalid' => boolean false       protected '_keysset' => boolean true       protected '_modulekey' => string 'module' (length=6)       protected '_controllerkey' => string 'controller' (length=10)       protected '_actionkey' => string 'action' (length=6)       protected '_dispatcher' =>          object(zend_controller_dispatcher_standard)[40]           protected '_curdirectory' => string '/applications/mamp/htdocs/selfstudy/zend/storefront/application/modules/storefront/controllers' (length=94)           protected '_curmodule' => string 'storefront' (length=10)           protected '_controllerdirectory' =>              array (size=1)               ...           protected '_defaultaction' => string 'index' (length=5)           protected '_defaultcontroller' => string 'index' (length=5)           protected '_defaultmodule' => string 'storefront' (length=10)           protected '_frontcontroller' => null           protected '_invokeparams' =>              array (size=3)               ...           protected '_pathdelimiter' => string '_' (length=1)           protected '_response' =>              object(zend_controller_response_http)[45]               ...           protected '_worddelimiter' =>              array (size=2)               ...       protected '_request' =>          object(zend_controller_request_http)[44]           protected '_paramsources' =>              array (size=2)               ...           protected '_requesturi' => string '/selfstudy/zend/storefront/public/index.php' (length=43)           protected '_baseurl' => string '/selfstudy/zend/storefront/public/index.php' (length=43)           protected '_basepath' => null           protected '_pathinfo' => string '' (length=0)           protected '_params' =>              array (size=3)               ...           protected '_rawbody' => null           protected '_aliases' =>              array (size=0)               ...           protected '_dispatched' => boolean true           protected '_module' => string 'storefront' (length=10)           protected '_modulekey' => string 'module' (length=6)           protected '_controller' => string 'index' (length=5)           protected '_controllerkey' => string 'controller' (length=10)           protected '_action' => string 'index' (length=5)           protected '_actionkey' => string 'action' (length=6)       protected '_isabstract' => boolean false       protected '_matchedpath' => null   'customroute' =>      object(zend_controller_router_route)[5]       protected '_translator' => null       protected '_locale' => null       protected '_istranslated' => boolean false       protected '_translatable' =>          array (size=0)           empty       protected '_urlvariable' => string ':' (length=1)       protected '_urldelimiter' => string '/' (length=1)       protected '_regexdelimiter' => string '#' (length=1)       protected '_defaultregex' => null       protected '_variables' =>          array (size=0)           empty       protected '_parts' =>          array (size=2)           0 => string 'test' (length=4)           1 => string 'route' (length=5)       protected '_defaults' =>          array (size=3)           'module' => string 'storefront' (length=10)           'controller' => string 'index' (length=5)           'action' => string 'index' (length=5)       protected '_requirements' =>          array (size=0)           empty       protected '_values' =>          array (size=0)           empty       protected '_wildcarddata' =>          array (size=0)           empty       protected '_staticcount' => int 2       protected '_isabstract' => boolean false       protected '_matchedpath' => null 

i don't know why not working expected. should easy task. many in advance advice!

update

for reason zend framework redirects request url

http://localhost:8888/selfstudy/zend/storefront/public/storefront/index/index/  

to

http://localhost:8888/index.php 

probably because of wrong/missing configuration inside application.ini?

update 2: mod_rewrite log

::1 - - [04/apr/2015:20:18:52 +0200] [localhost/sid#101001730][rid#10288b0a0/initial] (3) [perdir /applications/mamp/htdocs/selfstudy/zend/storefront/public/] add path info postfix: /applications/mamp/htdocs/selfstudy/zend/storefront/public/storefront -> /applications/mamp/htdocs/selfstudy/zend/storefront/public/storefront/test/route ::1 - - [04/apr/2015:20:18:52 +0200] [localhost/sid#101001730][rid#10288b0a0/initial] (3) [perdir /applications/mamp/htdocs/selfstudy/zend/storefront/public/] strip per-dir prefix: /applications/mamp/htdocs/selfstudy/zend/storefront/public/storefront/test/route -> storefront/test/route ::1 - - [04/apr/2015:20:18:52 +0200] [localhost/sid#101001730][rid#10288b0a0/initial] (3) [perdir /applications/mamp/htdocs/selfstudy/zend/storefront/public/] applying pattern '^.*$' uri 'storefront/test/route' ::1 - - [04/apr/2015:20:18:52 +0200] [localhost/sid#101001730][rid#10288b0a0/initial] (4) [perdir /applications/mamp/htdocs/selfstudy/zend/storefront/public/] rewritecond: input='/applications/mamp/htdocs/selfstudy/zend/storefront/public/storefront' pattern='-s' => not-matched ::1 - - [04/apr/2015:20:18:52 +0200] [localhost/sid#101001730][rid#10288b0a0/initial] (4) [perdir /applications/mamp/htdocs/selfstudy/zend/storefront/public/] rewritecond: input='/applications/mamp/htdocs/selfstudy/zend/storefront/public/storefront' pattern='-l' => not-matched ::1 - - [04/apr/2015:20:18:52 +0200] [localhost/sid#101001730][rid#10288b0a0/initial] (4) [perdir /applications/mamp/htdocs/selfstudy/zend/storefront/public/] rewritecond: input='/applications/mamp/htdocs/selfstudy/zend/storefront/public/storefront' pattern='-d' => not-matched ::1 - - [04/apr/2015:20:18:52 +0200] [localhost/sid#101001730][rid#10288b0a0/initial] (3) [perdir /applications/mamp/htdocs/selfstudy/zend/storefront/public/] add path info postfix: /applications/mamp/htdocs/selfstudy/zend/storefront/public/storefront -> /applications/mamp/htdocs/selfstudy/zend/storefront/public/storefront/test/route ::1 - - [04/apr/2015:20:18:52 +0200] [localhost/sid#101001730][rid#10288b0a0/initial] (3) [perdir /applications/mamp/htdocs/selfstudy/zend/storefront/public/] strip per-dir prefix: /applications/mamp/htdocs/selfstudy/zend/storefront/public/storefront/test/route -> storefront/test/route ::1 - - [04/apr/2015:20:18:52 +0200] [localhost/sid#101001730][rid#10288b0a0/initial] (3) [perdir /applications/mamp/htdocs/selfstudy/zend/storefront/public/] applying pattern '^(.*)$' uri 'storefront/test/route' ::1 - - [04/apr/2015:20:18:52 +0200] [localhost/sid#101001730][rid#10288b0a0/initial] (4) [perdir /applications/mamp/htdocs/selfstudy/zend/storefront/public/] rewritecond: input='/selfstudy/zend/storefront/public/storefront/test/route::storefront/test/route' pattern='^(/.+)(.+)::\\2$' => matched ::1 - - [04/apr/2015:20:18:52 +0200] [localhost/sid#101001730][rid#10288b0a0/initial] (5) setting env variable 'base' '/selfstudy/zend/storefront/public/' ::1 - - [04/apr/2015:20:18:52 +0200] [localhost/sid#101001730][rid#10288b0a0/initial] (3) [perdir /applications/mamp/htdocs/selfstudy/zend/storefront/public/] add path info postfix: /applications/mamp/htdocs/selfstudy/zend/storefront/public/storefront -> /applications/mamp/htdocs/selfstudy/zend/storefront/public/storefront/test/route ::1 - - [04/apr/2015:20:18:52 +0200] [localhost/sid#101001730][rid#10288b0a0/initial] (3) [perdir /applications/mamp/htdocs/selfstudy/zend/storefront/public/] strip per-dir prefix: /applications/mamp/htdocs/selfstudy/zend/storefront/public/storefront/test/route -> storefront/test/route ::1 - - [04/apr/2015:20:18:52 +0200] [localhost/sid#101001730][rid#10288b0a0/initial] (3) [perdir /applications/mamp/htdocs/selfstudy/zend/storefront/public/] applying pattern '^(.*)$' uri 'storefront/test/route' ::1 - - [04/apr/2015:20:18:52 +0200] [localhost/sid#101001730][rid#10288b0a0/initial] (2) [perdir /applications/mamp/htdocs/selfstudy/zend/storefront/public/] rewrite 'storefront/test/route' -> '/selfstudy/zend/storefront/public/index.php' ::1 - - [04/apr/2015:20:18:52 +0200] [localhost/sid#101001730][rid#10288b0a0/initial] (1) [perdir /applications/mamp/htdocs/selfstudy/zend/storefront/public/] internal redirect /selfstudy/zend/storefront/public/index.php [internal redirect] ::1 - - [04/apr/2015:20:18:52 +0200] [localhost/sid#101001730][rid#102896c80/initial/redir#1] (3) [perdir /applications/mamp/htdocs/selfstudy/zend/storefront/public/] strip per-dir prefix: /applications/mamp/htdocs/selfstudy/zend/storefront/public/index.php -> index.php ::1 - - [04/apr/2015:20:18:52 +0200] [localhost/sid#101001730][rid#102896c80/initial/redir#1] (3) [perdir /applications/mamp/htdocs/selfstudy/zend/storefront/public/] applying pattern '^.*$' uri 'index.php' ::1 - - [04/apr/2015:20:18:52 +0200] [localhost/sid#101001730][rid#102896c80/initial/redir#1] (4) [perdir /applications/mamp/htdocs/selfstudy/zend/storefront/public/] rewritecond: input='/applications/mamp/htdocs/selfstudy/zend/storefront/public/index.php' pattern='-s' => matched ::1 - - [04/apr/2015:20:18:52 +0200] [localhost/sid#101001730][rid#102896c80/initial/redir#1] (1) [perdir /applications/mamp/htdocs/selfstudy/zend/storefront/public/] pass through /applications/mamp/htdocs/selfstudy/zend/storefront/public/index.php 

i think problem in .htaccess use .htaccess content:

rewriteengine on

rewritecond %{request_filename} -s [or]

rewritecond %{request_filename} -l [or]

rewritecond %{request_filename} -d

rewriterule ^.*$ - [nc,l]

rewritecond %{request_uri}::$1 ^(/.+)(.+)::\2$

rewriterule ^(.*)$ - [e=base:%1]

rewriterule ^(.*)$ %{env:base}index.php [nc,l]

** .htaccess hidden file in /public directory


Comments

  1. Nice articel, This article help me very well. Thank you. Also please check my article on my site Know All About Htaccess Tutorial.
    In link article we will learn about How to use .htaccess? The Htaccess document is placed in a directory on the web server. When done, it will be deployed from the Apache web server when a request is made from that directory.

    ReplyDelete

Post a Comment

Popular posts from this blog

How to run C# code using mono without Xamarin in Android? -

html - grunt SVG to webfont -

c# - SharpSsh Command Execution -