Skip to content
This repository was archived by the owner on Nov 27, 2020. It is now read-only.

redirect /app.php to prevent duplicate content #503

Merged
merged 2 commits into from
Mar 21, 2013
Merged

redirect /app.php to prevent duplicate content #503

merged 2 commits into from
Mar 21, 2013

Conversation

Tobion
Copy link
Contributor

@Tobion Tobion commented Mar 1, 2013

Improved version of #497. This time it's compatible with Apache < 2.3.9 by not using the END flag. It also features default compatibility with apache aliases (inspired by Zend). And it improves the rewriting performance for the homepage by preventing the process to apply to each DirectoryIndex file.

Now I could also make the startpage work when mod_rewrite is not available.

I tested it thoroughly and also debugged apache rewriting to see what's happening.
It was quite hard to find out how to achieve all that. This resource helped quite a bit.

May be good if someone else can confirm all works.

Example behavior for each scenario:

With mod_rewrite:

  • / -> internally rewritten to use front controller (app.php)
  • /path -> internally rewritten to use front controller
  • /app.php/path -> external permanent redirect to /path to prevent duplicate content
  • /app.php or /app.php/-> external permanent redirect to / to prevent duplicate content
  • /app.phpF stays as-is

Without mod_rewrite but with mod_alias (default module):

  • / -> external temporary redirect to /app.php/ so it's explicit and all generated links on the startpage also work with the base path prepended
  • /path -> stays as-is and would probably return a 404 (we cannot safely and easily redirect with mod_alias to /app.php/path because we don't know if the request references a real file like CSS)
  • /app.php/path -> stays as-is and works because the front controller is given
  • /app.php -> stays as-is and works because the front controller is given

In an aliased environment with mod_rewrite:

  • /myproject/ -> internally rewritten to use front controller (app.php)
  • /myproject/path -> internally rewritten to use front controller
  • /myproject/app.php/path -> external permanent redirect to /myproject/path to prevent duplicate content
  • /myproject/app.php -> external permanent redirect to /myproject/ to prevent duplicate content

In an aliased environment without mod_rewrite:

  • /myproject/ -> stays as-is and works because it uses the DirectoryIndex definition (but the links will not work)
  • /myproject/path -> stays as-is and would probably return a 404 (except there is such a file)
  • /myproject/app.php/path -> stays as-is and works because the front controller is given
  • /myproject/app.php -> stays as-is and works because the front controller is given

This time it's compatible with Apache < 2.3.9 by not using the END flag. It also features default compatibility with apache aliases (inspired by Zend). And it improves the rewriting performance for the homepage by preventing the process to apply to each DirectoryIndex file
@colinfrei
Copy link

Tested as well on Apache 2.2.16

# This reduces the matching process for the startpage (path "/") because
# otherwise apache will apply the rewritting rules to each configured
# DirectoryIndex file needlessly (e.g. index.php, index.html, index.pl).
DirectoryIndex
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DirectoryIndex without any argument looks weird to me. I don't see any mention of this syntax (and what it does) in the Apache docs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It just specifies no index file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed as part of another improvement

@Tobion
Copy link
Contributor Author

Tobion commented Mar 1, 2013

ping @gimler @vxf @neilferreira considering you commented on the intial PR

@gimler
Copy link

gimler commented Mar 1, 2013

it works for me server version: Apache/2.2.22 (Ubuntu)

@Tobion
Copy link
Contributor Author

Tobion commented Mar 1, 2013

@gimler did you also test it in an aliased environment?

@gimler
Copy link

gimler commented Mar 1, 2013

no only simple vhost

@jalliot
Copy link
Contributor

jalliot commented Mar 2, 2013

@Tobion if it is merged here, you should also probably submit an equivalent PR to symfony's ApacheMatcherDumper.

@Tobion
Copy link
Contributor Author

Tobion commented Mar 2, 2013

@jalliot you are right. Thanks for the hint. The apache dumper is also quite strange. For example if you request it with /app.php/... the dumped routes wont even be used.

@Tobion
Copy link
Contributor Author

Tobion commented Mar 21, 2013

Now I also could also make the startpage work when mod_rewrite is not available.
I also updated the examples in the PR description. @fabpot it's tested and should be ready.

fabpot added a commit that referenced this pull request Mar 21, 2013
This PR was merged into the 2.2 branch.

Commits
-------

ea255c0 made the startpage work when mod_rewrite is not available
e97e7fa redirect /app.php to prevent duplicate content

Discussion
----------

redirect /app.php to prevent duplicate content

Improved version of #497. This time it's compatible with Apache < 2.3.9 by not using the END flag. It also features default compatibility with apache aliases (inspired by [Zend](https://github.com/zendframework/ZendSkeletonApplication/blob/master/public/.htaccess)). And it improves the rewriting performance for the homepage by preventing the process to apply to each DirectoryIndex file.

Now I also could also make the startpage work when mod_rewrite is not available.

I tested it thoroughly and also debugged apache rewriting to see what's happening.
It was quite hard to find out how to achieve all that. [This resource](http://stackoverflow.com/questions/7798099/how-to-block-multiple-mod-rewrite-passes-or-infinite-loops-in-a-htaccess-cont) helped quite a bit.

May be good if someone else can confirm all works.

Example behavior for each scenario:

With mod_rewrite:
- `/` -> internally rewritten to use front controller (`app.php`)
- `/path` -> internally rewritten to use front controller
- `/app.php/path` -> external permanent redirect to `/path` to prevent duplicate content
- `/app.php` or `/app.php/`-> external permanent redirect to `/` to prevent duplicate content
- `/app.phpF` stays as-is

Without mod_rewrite but with mod_alias (default module):
- `/` -> external temporary redirect to `/app.php/` so it's explicit and all generated links on the startpage also work with the base path prepended
- `/path` -> stays as-is and would probably return a 404 (we cannot safely and easily redirect with mod_alias to `/app.php/path` because we don't know if the request references a real file like CSS)
- `/app.php/path` -> stays as-is and works because the front controller is given
- `/app.php` -> stays as-is and works because the front controller is given

In an aliased environment with mod_rewrite:
- `/myproject/` -> internally rewritten to use front controller (`app.php`)
- `/myproject/path` -> internally rewritten to use front controller
- `/myproject/app.php/path` -> external permanent redirect to `/myproject/path` to prevent duplicate content
- `/myproject/app.php` -> external permanent redirect to `/myproject/` to prevent duplicate content

In an aliased environment without mod_rewrite:
- `/myproject/` -> stays as-is and works because it uses the DirectoryIndex definition (but the links will not work)
- `/myproject/path` -> stays as-is and would probably return a 404 (except there is such a file)
- `/myproject/app.php/path` -> stays as-is and works because the front controller is given
- `/myproject/app.php` -> stays as-is and works because the front controller is given

---------------------------------------------------------------------------

by colinfrei at 2013-03-01T12:10:59Z

Tested as well on Apache 2.2.16

---------------------------------------------------------------------------

by Tobion at 2013-03-01T12:42:58Z

ping @gimler @vxf @neilferreira considering you commented on the intial PR

---------------------------------------------------------------------------

by gimler at 2013-03-01T12:51:35Z

it works for me server version: Apache/2.2.22 (Ubuntu)

---------------------------------------------------------------------------

by Tobion at 2013-03-01T14:33:20Z

@gimler did you also test it in an aliased environment?

---------------------------------------------------------------------------

by gimler at 2013-03-01T14:38:27Z

no only simple vhost

---------------------------------------------------------------------------

by jalliot at 2013-03-02T15:48:08Z

@Tobion if it is merged here, you should also probably submit an equivalent PR to symfony's [ApacheMatcherDumper](https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Routing/Matcher/Dumper/ApacheMatcherDumper.php).

---------------------------------------------------------------------------

by Tobion at 2013-03-02T21:11:40Z

@jalliot you are right. Thanks for the hint. The apache dumper is also quite strange. For example if you request it with `/app.php/...` the dumped routes wont even be used.

---------------------------------------------------------------------------

by Tobion at 2013-03-21T14:27:51Z

Now I also could also make the startpage work when mod_rewrite is not available.
I also updated the examples in the PR description. @fabpot it's tested and should be ready.
@fabpot fabpot merged commit ea255c0 into symfony:2.2 Mar 21, 2013
@Tobion Tobion deleted the htaccess branch March 21, 2013 15:39
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants