-- David Muir <
[hidden email]> wrote
(on Wednesday, 13 June 2012, 10:12 PM +1000):
> I'm not sure if this is a Zend/Mvc/Router issue or a server config issue, but I
> noticed this when going through the Rob Allen's zf2 tutorial.
>
>
http://zf-tutorial/album - 200 - works fine
>
http://zf-tutorial/album/ - 404 - The requested URL could not be matched by
> routing.
>
> I'm assuming that because it contains a slash, it's matching the optional part
> of the route :controller[/:action][/:id], and therefore attempting to run an
> action called "" (empty string). I tried adding public function Action(){}, but
> that didn't make a difference.
>
> Is the only way to solve this to be to strip the trailing slash via .htaccess,
> or conversely make the slash required eg: :controller/[:action/][:id/], and
> automatically append the trailing slash via .htaccess, if the file doesn't
> exist?
> I'm guessing that's the better solution than having the router handle the
> situation, as it affects stats and SEO stuff (duplicate content). It did take
> me by surprise though, that the router crapped out here.
You hit the nail on the head when you mentioned the duplicate content
issue. It's typically better not to have two urls respond to the same
thing.
Ideally, you should either have a rule in .htaccess or in PHP that
redirects if the path_info ends in a slash, using a 301 (moved
permanently) status. (Using PHP would be more portable, particularly
when you move to some fastcgi platforms that do not support URL
rewriting as thoroughly as mod_rewrite.)
--
Matthew Weier O'Phinney
Project Lead |
[hidden email]
Zend Framework |
http://framework.zend.com/PGP key:
http://framework.zend.com/zf-matthew-pgp-key.asc