I'm using FallbackResource directive to route all web requests via front controller /index.php:

FallbackResource /index.php

It works great but one thing bothers me. It's the fact that /index.php is still available directly - same resource has two URL-s:

  • http://www.example.com/resource-path
  • http://www.example.com/index.php/resource-path

I was hoping FallbackResource will deal with this so that only main URL is available because this could pose a SEO problem. What's the best way to fix this?

  • It's shocking that nobody has answered this. I am wondering the same thing. – Yes Barry Mar 6 at 16:44

I haven't found a solution in Apache for this. The only solution I've found for this is in handling it in PHP which almost defeats the purpose of using FallbackResource /index.php in the first place.

if (preg_match('#^/index.php#', $_SERVER['REQUEST_URI'])) {
    $redirect = preg_replace('#^/index.php#', '', $_SERVER['REQUEST_URI']);
    if (empty($redirect)) {
        $redirect = '/'; // in case request is domain.com/index.php with no trailing slash
    header('Location: ' . $redirect);

This is not ideal but it works. It's odd there's so little information about the duplicate URLs issue with FallbackResource. Nevertheless, this solution did not suffice IMO so what I did personally is go back to mod_rewrite.

RewriteEngine On
RewriteRule ^index\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^ %{ENV:BASE}/index.php [L]

Hope this helps you at least. I tried a bounty but nobody seems to have an answer.

  • Thank you... problem confirmation is almost as good as solution :) – gseric Mar 12 at 17:38

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.