Unusual redirect, regex is giving me a headache

Discussion in 'Apache' started by firewind, Sep 4, 2008.

  1. #1
    I have an interesting redirect problem that so far has eluded me, and I'm quite willing to pay for a solution if necessary.

    Basically, when someone goes to http://www.mysite.com/N (with N being any six digit number), I want to redirect them to an URL that loads another script, with N as a variable. I only want this to happen with numerical digits; alphanumeric URLs would be handled like any other 404 error.

    I've been trying to do this in PHP using a custom 404 page but am running into a browser issue (it's working in Firefox but not in IE), so I think I may need to do this in .htaccess.

    For example, see the following link in Firefox (to see it work), then in IE (to see it break):

    http://www.re-tp.com/109332

    I've been perusing my Apache books but haven't been able to figure out the right regex. If I'm thinking about this clearly (probably not, mod_rewrite gives me a headache) the regex would look something like:

    /\d{6}$

    but that doesn't seem to work and I'm stumped. Any ideas?
     
    firewind, Sep 4, 2008 IP
  2. DomainCo.US

    DomainCo.US Well-Known Member

    Messages:
    2,124
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    100
    #2
    Not good in regex either. How about creating custom 404 page and then check for the 6 digit programmatically?
     
    DomainCo.US, Sep 4, 2008 IP
  3. firewind

    firewind Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Well, that's what I'm presently doing but the redirect fails in Internet Explorer, and I don't understand why.

    If you go to:
    http://www.re-tp.com/asdf
    and then
    http://www.re-tp.com/111541

    you'll see that my custom 404 PHP script is presently working, but it fails when it gets to the redirect in Internet Explorer. It works in Firefox.

    I figured there had to be some way to do this in .htaccess ... no go?
     
    firewind, Sep 4, 2008 IP
  4. DomainCo.US

    DomainCo.US Well-Known Member

    Messages:
    2,124
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    100
    #4
    try this in htaccess
    ErrorDocument 404 /domain.com/404e.php
    in 404e.php get the REQUEST_URI
     
    DomainCo.US, Sep 4, 2008 IP
  5. firewind

    firewind Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Again (as I've stated in every post), that's what I'm presently doing. I have a custom PHP page that works in Firefox but not in Internet Explorer. I came here to find out if I could bypass all that and do it via .htaccess. What I'm hearing is that it isn't possible and I should just go to the PHP forums. Is anybody else reading this, is it really not possible?

    I've tried posting my PHP code but the forum won't let me. I'll try again:

    
    <?php
    
    require_once ('lib-common.php');
    
    //$parm = preg_replace('/[^a-z0-9\-_]/', '', $_SERVER['REQUEST_URI']);
    $parm = COM_applyFilter($_SERVER['REQUEST_URI']);
    $pLen = strlen($parm)-1;
    $parm = substr($parm,1,$pLen);
    $pLength = strlen($parm);
    
    if (is_numeric($parm) && $pLength == 6 ){
    //    echo COM_refresh($_CONF['site_url'] . '/scriptname.php?id=' . $parm);
        echo COM_refresh('http://www.lewistonclarkstonidx.com/listing.php?mls=' . $parm . "&site_id=1485");
        exit;
    }
    
    if (isset ($_SERVER['SCRIPT_URI'])) {
        $url = strip_tags ($_SERVER['SCRIPT_URI']);
    } else {
        $pos = strpos ($_SERVER['REQUEST_URI'], '?');
        if ($pos === false) {
            $request = $_SERVER['REQUEST_URI'];
        } else {
            $request = substr ($_SERVER['REQUEST_URI'], 0, $pos);
        }
        $url = 'http://' . $_SERVER['HTTP_HOST'] . strip_tags ($request);
    }
    $display = COM_siteHeader ('menu', $LANG_404[1]);
    $display .= COM_startBlock ($LANG_404[1]);
    $display .= sprintf ($LANG_404[2], $url);
    $display .= $LANG_404[3];
    $display .= COM_endBlock ();
    $display .= COM_siteFooter ();
    
    echo $display
    
    ?>
    
    Code (markup):
     
    firewind, Sep 6, 2008 IP