Development

#1482 (Workaround required for apache URL bug)

You must first sign up to be able to contribute.

Ticket #1482 (closed defect: worksforme)

Opened 3 years ago

Last modified 2 years ago

Workaround required for apache URL bug

Reported by: halfer Assigned to:
Priority: major Milestone:
Component: askeet Version: 1.0.0-rc1
Keywords: mod_rewrite front controller apache bug Cc:
Qualification: Unreviewed

Description

** Technically not a symfony problem, but perhaps a workaround can be proposed, or can the front controller be called another way? **

Consider the following URL:

http://localhost:8005/module/action/a%2Fb

Here I have an action and module, with a routed parameter "a/b" in which the slash character has been escaped so as to distiguish it from a slash character. Unfortunately symfony does not gain control at all, as Apache incorrectly unescapes the URL before passing it to mod_rewrite, resulting in a generic Apache 404. Presumably this is passed, and so the htaccess is not seen at all:

http://localhost:8005/module/action/a/b

So as far as I can tell, mod_rewrite does not even get a look-in, and adding NE (no escape) to RewriteRule does not appear to make a difference.

Problem spotted elsewhere on the web:

http://issues.apache.org/bugzilla/show_bug.cgi?id=34602 http://issues.apache.org/bugzilla/show_bug.cgi?id=32328#c11 http://meandeu.com/article/7c257722-c732-a973-39e0-254ca460184b http://mail-archives.apache.org/mod_mbox/httpd-bugs/200510.mbox/%3C20051010104015.2C012243@ajax.apache.org%3E

Change History

02/20/07 18:50:51 changed by halfer

This is a bit of a hack, but it's pretty clean. Add this to the (virtual) server container in the Apache config:

# Catch pesky %2f Apache bug 'not founds'
ErrorDocument 404 /index.php

Disadvantages:

  1. This change is not possible for users on shared hosts
  2. It doesn't work for alternative front controllers (eg if index.php is specified in this workaround, then using frontend_dev.php with a URL containing %2f will result in a 404 within symfony.

02/21/07 12:27:35 changed by halfer

I have fixed issue 2 above. Replace the virtual server container directive above with this:

# Catch pesky %2f Apache bug 'not founds'
ErrorDocument 404 /error_handler.php

And then create "error_handler.php" in your web folder:

<?php
define('DEV_FRONT_CONTROLLER', 'frontend_dev.php');
define('DEV_FRONT_CONTROLLER_URI', '/' . DEV_FRONT_CONTROLLER);
define('PROD_FRONT_CONTROLLER', 'index.php');
define('PROD_FRONT_CONTROLLER_URI', '/' . PROD_FRONT_CONTROLLER);

// Hack the front controller name for the benefit of the routing module
$_SERVER['SCRIPT_NAME'] = DEV_FRONT_CONTROLLER_URI;

// Switch to the appropriate front controller
$uri = $_SERVER['REQUEST_URI'];
if (substr($uri, 0, strlen(DEV_FRONT_CONTROLLER_URI)) == DEV_FRONT_CONTROLLER_URI)
{
  require DEV_FRONT_CONTROLLER;
}
else
{
  require PROD_FRONT_CONTROLLER;
}

I haven't worked out how to fix issue 1 in a shared Apache environment, other than avoiding %2f, or urlencoding/decoding twice, which is a pain.

02/21/07 12:41:10 changed by halfer

Hmm, the above strangely works but, for correctness, it should be:

<?php
define('DEV_FRONT_CONTROLLER', 'frontend_dev.php');
define('DEV_FRONT_CONTROLLER_URI', '/' . DEV_FRONT_CONTROLLER);
define('PROD_FRONT_CONTROLLER', 'index.php');
define('PROD_FRONT_CONTROLLER_URI', '/' . PROD_FRONT_CONTROLLER);

// Switch to the appropriate front controller
$uri = $_SERVER['REQUEST_URI'];
if (substr($uri, 0, strlen(DEV_FRONT_CONTROLLER_URI)) == DEV_FRONT_CONTROLLER_URI)
{
  $_SERVER['SCRIPT_NAME'] = DEV_FRONT_CONTROLLER_URI;
  require DEV_FRONT_CONTROLLER;
}
else
{
  $_SERVER['SCRIPT_NAME'] = PROD_FRONT_CONTROLLER_URI;
  require PROD_FRONT_CONTROLLER;
}

02/08/08 23:12:02 changed by dwhittle

  • status changed from new to closed.
  • resolution set to worksforme.
  • component set to askeet.
  • qualification set to Unreviewed.

This should be moved to dev mailing list..

03/21/08 17:45:13 changed by fabien

You can use the Apache AllowEncodedSlashes directive and set it to on to accept %2F

The Sensio Labs Network

Since 1998, Sensio Labs has been promoting the Open-Source software movement by providing quality web application development, training, consulting.
Sensio Labs also supports several large Open-Source projects.