php - Using Zend framework to redirect/forward (similar to 301 status) old URLs to new controllers/actions -
i have rather old website i've fed refactoring i'm rebuilding.
the old urls don't have naming consistency me create sort of rule so, possible have sort of router/controller forwards ($this->_forward()) old urls new location?
for instance when i'm calling http://www.example.com/this-is-a-url-with-a-random-name.php forward http://www.example.com/url/random-name ...
maybe match exist in array key old url , value new location?
or trying re-invent wheel , should stick ol' .htaccess rules 301 redirects?
(i hope makes sense?)
cheers, angel
i'll start off recommending using apache config place rewrites if possible. it's faster both using .htaccess , zend framework application.
i'll want use 301 redirects best search engines when content has been moved permanently.
if want use zend framework application , if have bunch of urls may have different structures, best place in default error controller 'last ditch effort'. reason if have url /myoldurl
doesn't exist (but on redirect list) , implement in future it's own controller/module - controller automatically take over.
inside erroraction()
there switch decides if error 404 or 500.
inside 404 block can add code redirect. not complete code, on , insert missing pieces of data needed.
// [code omitted] switch ($errors->type) { case zend_controller_plugin_errorhandler::exception_no_route: case zend_controller_plugin_errorhandler::exception_no_controller: case zend_controller_plugin_errorhandler::exception_no_action: // original request string ie: /myoldurl $pathinfo = $this->_request->getpathinfo(); // decide if pathinfo in redirect list if ($pathinfo in list of old urls) { // , $newurl list $newurl = list of new urls; // set redirect code 301 instead of default 302 $this->_helper->redirector->setcode(301); $this->_redirect($newurl); } // 404 error -- controller or action not found $this->getresponse()->sethttpresponsecode(404); $this->view->message = 'page not found'; break; //[...]
Comments
Post a Comment