Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jul 2005
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Weird problem with header("Location: ...")

    I'm experiencing a weird and very frustrating problem. I am trying to run our page via the www. prefix instead of dropping the prefix as our page seems to run better while using the prefix.

    When I try to use

    header("Location: http://www.mydomain.com/path/to/file/index.html")

    it indeed redirects me to this page, however, it redirects me to

    http://mydomain.com/path/to/file/index.html

    instead of

    http://www.mydomain.com/path/to/file/index.html.

    Why would this happen? I thought it maybe had something to do with the quotes, so I've tried single and double quotes both with the same results.

    Any ideas?

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Your hosting company probably has a mod rewrite for all domains. Does the www stick around if you just type it into the browser?

  • #3
    New Coder
    Join Date
    Jul 2005
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yes, when i type it into the browser, it goes to the www prefix just not when I use the header function in php.

    I'm going to test this as a stand alone program (one liner) and see what I come up with.

  • #4
    New Coder
    Join Date
    Jul 2005
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Alright, so I figured it out after using a plug-in for firefox called live http headers was able to determine that the header was being sent back as HTTP Error 301 - Moved permanently and it therefore tried the domain without the www prefix.

    This was fixed only when I changed the Location header from this

    header("Location: http://www.ourdomain.com/path/to/dir")

    to this

    header("Location: http://www.ourdomain.com/path/to/dir/index.php")

    notice the index.php at the end of the path... For some reason it will not redirect to a directory through the www prefix.

    Hope this helps someone else as well,
    Tylor


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •