views:

90

answers:

2

I'm using the Zend Router and so things like (/ and /index.php) or (/about and /index.php/about) ends up as the same here.

However, /index.php/whatever should not exist as it is the exactly same resource as /whatever so it doesn't make a sense the duplication.

How do I avoid this?

Even http://zendframework.com/manual/en/zend.controller.router.html and http://zendframework.com/index.php/manual/en/zend.controller.router.html both exists. It doesn't make any sense at all...

A: 

1) Don't link to it (like the urls in your question) and let it be a hidden feature. It won't matter, basically.
or
2) Add a rewrite-rule to strip out /index.php from any request containing it. You have to be sure to forward it to index.php so that you still can handle it, and you probably want to send a status code beginning with 3.

chelmertz
Not linking is kind of a work-around (and I 'just do that' right now). And if you use Zend Router url helper to create internal links (really useful) consider that it may take just a random user attaching index.php to a link of yours somewhere (for whatever reason) and you risk wasting resources with web crawlers (even if you use redirections like what you said in (2)).
Henrique Vicente
@henriquev: rewriting requests should be on server level and not via Zend Router, to waste the least resources. That's how the standard rewriting is used for every ZF app, if you add one more rule for this case (/index.php.*), it wouldn't impact to much. I guess you need to benchmark your app to see if it impacts you. Via the right redirection header, your SEO won't be severed much either. That is, if the user even cares enough to modify links. I think this whole question is a non issue really.
chelmertz
A: 

Seems that your mod_rewrite is not configured properly (is mod_rewrite enabled in Apache? Is .htaccess configured properly?). When it would be, you wouldn't have to type index.php at all.

Edit:

RewriteEngine On

RewriteCond %{REQUEST_URI} ^index.php [OR]

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
takeshin
He doesn't *have* to type index.php but he notices it leads to the same page when he *does type* `index.php` manually.
chelmertz
mod_rewrite is enabled and in use.As I said, I may type or not index.php.So, what my rewrite rules does?They check if there is a file at that path, if not they redirect to index.php.So when there is a /index.php of course it'd not redirect, but just load the index.php anyway. But if there is something like /index.php/help it is going to work as /help. And that means what? That the problem/solution lies in the PHP side, more precise: it's something in the zend router (like it not using the complete path, but a subset of it).
Henrique Vicente
I'have added sample code *not tested* to my answer.
takeshin