#1
  1. Mad Scientist
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2007
    Location
    North Yorkshire, UK
    Posts
    3,661
    Rep Power
    4123

    Unexpected Redirect, is this behavior normal?


    I am a PHP developer with nearly 8 years experience, most of which has been spent developing on a LAMP stack.

    Today I was building a really simple form, and while testing locally I found that it appeared not to send any data and that the $_POST array in PHP was empty.

    A live hearders puglin for firefox showed me what was happening.

    My form's action was

    Code:
    http://localhost/project-name/landing-page
    The file could be accessed at

    Code:
    http://localhost/project-name/landing-page/
    or
    http://localhost/project-name/landing-page/index.php
    becuase I had omitted the trailing / for the directory name, apache was issuing a 301 redirect to include it, ie

    Code:
    from
    http://localhost/project-name/landing-page
    to
    http://localhost/project-name/landing-page/
    This is something I have never seen before!

    Is it a config setting that I have locally?
    Is this normal behavior?

    running PHP 5.3.1 on Apache 2 on Windows7 (64) as x86
    Last edited by Northie; May 25th, 2012 at 05:48 AM. Reason: Names removed to protect thew innocent
    I said I didn't like ORM!!! <?php $this->model->update($this->request->resources[0])->set($this->request->getData())->getData('count'); ?>

    PDO vs mysql_* functions: Find a Migration Guide Here

    [ Xeneco - T'interweb Development ] - [ Are you a Help Vampire? ] - [ Read The manual! ] - [ W3 methods - GET, POST, etc ] - [ Web Design Hell ]
  2. #2
  3. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,317
    Rep Power
    7170
    I think the DirectorySlash directive can be used to turn this off, but I don't think it's something you want to do.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  4. #3
  5. CSS & JS/DOM Adept
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jul 2004
    Location
    USA (verifiably)
    Posts
    20,124
    Rep Power
    4303
    Yes, it is normal, and no, you don't want to disable that feature.

    As mentioned in the documentation, two reasons that you want that feature are:
    Originally Posted by httpd.apache.org
    • DirectoryIndex will be evaluated only for directories requested with trailing slash.
    • Relative URL references inside html pages will work correctly.
    Spreading knowledge, one newbie at a time.

    Check out my blog. | Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Common CSS Mistakes | Common JS Mistakes

    Remember people spend most of their time on other people's sites (so don't violate web design conventions).

IMN logo majestic logo threadwatch logo seochat tools logo