in reply to SSI or .HTACCESS for CGI

$a = $ENV{REQUEST_URI}; $a =~ s|(/.*/)|$1|i; $a = $1; $sth = $dbh->prepare("SELECT * FROM category WHERE url=?"); $rows = $sth->execute($a);
See in my databse I have it so each category has its url so heres and example

Category: Accessories URL: /Snowmobile/Accesories/
See how would I make it so they went to the url without a trailing slash like http://someurl.com/shop/Snowmobile/Accesories

and in my code it doesnt get it right cause the /shop/ is in $a, I just need an idea how I would do this.

Replies are listed 'Best First'.
Re: Re: SSI or .HTACCESS for CGI
by Kanji (Parson) on Nov 10, 2002 at 19:37 UTC

    You can be a little more selective in your matching, and include logic to append a trailing slash if there isn't one already.

    if ( $ENV{'REQUEST_URI'} =~ m|\A/shop(/.*)$| ) { my $url = $1; $url .= '/' if $url !~ m|/$|; $sth = $dbh->prepapre("..."); # ... }

    However, if you're working with real directories, you shouldn't encounter the trailing slash problem as Apache automatically redirects such requests to the proper location IIRC.

    BTW, is there anything else in /shop/? If not, rather than using physical directories, why not rename your script to 'shop'?

    You wouldn't need to create any subdirectories then as they'd all be virtual extensions of your CGI, with the requested directory appearing in $ENV{'PATH_INFO'} alread minus the /shop/ portion but definitely in need of some trailing slash massaging.

        --k.