Results 1 to 14 of 14

Thread: Redirect based on HTTP_REFERER

  1. #1
    Roll Tide! mobilebadboy's Avatar
    Join Date
    Apr 2004
    Location
    Mobile, AL
    Posts
    428

    Redirect based on HTTP_REFERER

    Anyone know why this won't redirect, it just sits there and sits there and sits there. If I try to echo something out, or do pretty much anything else aside from header(), it works.



    PHP Code:
    <?
    if(eregi("some_website",$_SERVER['HTTP_REFERER'])) 
       { 
        
    header('Location:http://visualintensity.com');
       }
    ?>
    Shawn Kerr .com

  2. #2
    The manual for header has a space, and that's how I do it on all my sites.. Like this:

    PHP Code:
    header('Location: http://www.example.com/'); 
    Note the space between Location: and http://

    Maybe that's it?

  3. #3
    Roll Tide! mobilebadboy's Avatar
    Join Date
    Apr 2004
    Location
    Mobile, AL
    Posts
    428
    I've never noticed a difference with or without the space, or really paid attention.

    Either way, that wasn't it.
    Shawn Kerr .com

  4. #4
    Do you have any code before this happens that prints to the screen? Nothing can be echoed to the browser before the header code can be used.

    Create a blank php page with *just* the header code in it and see if that works.

  5. #5
    Roll Tide! mobilebadboy's Avatar
    Join Date
    Apr 2004
    Location
    Mobile, AL
    Posts
    428
    This is the first code that's output, above my DOCTYPE and everything else. I'm redirecting an existing link to my site, so there's no way to check if the code works other than to check the particular page it's linking to.

    The overall code works. I can echo out the referring link. I can kill it, die(), and do anything else with it. But the redirect doesn't work. I've even cleared my .htaccess to make sure there wasn't any confusion with my rewrites/redirects in that code. But I get the same result.
    Shawn Kerr .com

  6. #6
    Testing a link: http://www.lit.org/shawn

    Shawn, The above link tests your code you posted EXACTLY as you posted it. I have "somesite" set to websitepublisher.net It works on my server.

  7. #7
    Roll Tide! mobilebadboy's Avatar
    Join Date
    Apr 2004
    Location
    Mobile, AL
    Posts
    428
    Weird. Ok go here and click the link to my site, in the post by Mark.

    http://www.htmlforums.com/showthread.php?threadid=8663

    I have it set to "htmlforums". For me, it just sits there and sits there.
    Shawn Kerr .com

  8. #8
    That is odd, I'm trying it from that link too and it's just sitting there. Can you post the entire index file from that directory?

  9. #9
    Administrator Chris's Avatar
    Join Date
    Feb 2003
    Location
    East Lansing, MI USA
    Posts
    7,055
    Are you printing out anything on the page? If you send the browser a redirect and then print something out it might get confused. You shouldn't have any echos or prints in that file.
    Chris Beasley - My Guide to Building a Successful Website[size=1]
    Content Sites: ABCDFGHIJKLMNOP|Forums: ABCD EF|Ecommerce: Swords Knives

  10. #10
    Roll Tide! mobilebadboy's Avatar
    Join Date
    Apr 2004
    Location
    Mobile, AL
    Posts
    428
    Hmm, weird thing I just noticed. If I hit the Stop button on my browser, it redirects. But the page stops loading of course.

    My site is broken into multiple modules, so there's no way to paste in a full page without opening several different files. That whole page is just (X)HTML. There's a header file that's used throughout every page (where I'm placing the code). It's basic header stuff (DOCTYPE, head tags, meta tags, stylesheet code, title tags, etc).

    My site is nothing but includes and a simple if/else statement that changes the title tag based on the page. No echo/prints.

    Ah well, I'll figure it out. It's something with that header() function because even a typical meta refresh works. But that still lands on the page, then redirects.
    Shawn Kerr .com

  11. #11
    Roll Tide! mobilebadboy's Avatar
    Join Date
    Apr 2004
    Location
    Mobile, AL
    Posts
    428
    I got it straightened out by just using the htaccess file. Although I still played hell with that for about 30 minutes before I finally ran across a page that explained something no other site had. The way I was trying to go about it, the server kept trying to reexecute the htaccess file, putting it in an infinite loop. I think it's the same thing that was causing the problem earlier even with the PHP redirect.

    I was able to redirect to other sites, but not my front page.

    But a simple check that the requested uri was /flash/, everything works as it should.



    Code:
    RewriteCond %{HTTP_REFERER} ^http://(www\.)?domain.com/.*$
    RewriteCond %{REQUEST_URI} ^/flash/
    RewriteRule \.*$ http://visualintensity.com [L,R]
    Shawn Kerr .com

  12. #12
    I assume you weren't putting the php file in /flash then? If you had put the .htaccess file in the /flash directory no loop should have happened even without the uri check. Same things goes for the php. I had a feeling it was in a loop. That's what it felt like.

  13. #13
    Roll Tide! mobilebadboy's Avatar
    Join Date
    Apr 2004
    Location
    Mobile, AL
    Posts
    428
    Well, I put the PHP in my header.php file. Every page on the site shares that file. My htaccess file in root.
    Shawn Kerr .com

  14. #14
    Quote Originally Posted by mobilebadboy
    Well, I put the PHP in my header.php file. Every page on the site shares that file. My htaccess file in root.
    That's probably why. It was trying to redirect to your main page and the referer was the same so it looped.

    I usually put my redirects in the folder they are redirecting beause I'm prone to this kind of looping too

Similar Threads

  1. redirect a to website
    By ronp in forum General Management Issues
    Replies: 2
    Last Post: 04-08-2004, 11:54 PM
  2. Redirect
    By k0r54 in forum HTML, CSS, Layout, and Design
    Replies: 3
    Last Post: 03-28-2004, 03:40 PM
  3. need to exclude one page from a general .htaccess redirect
    By Apollo in forum General Management Issues
    Replies: 1
    Last Post: 01-10-2004, 01:56 PM
  4. redirect with htaccess
    By albsure in forum Website Programming & Databases
    Replies: 6
    Last Post: 12-07-2003, 09:40 AM
  5. Redirect
    By lemon in forum Search Engine Optimization
    Replies: 1
    Last Post: 09-09-2003, 12:47 PM

Bookmarks

Posting Permissions

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