1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Help with mod_rewrite?

Discussion in 'Apache' started by Owlcroft, Mar 23, 2004.

  1. #1
    My domain is hosted on an ISP. That ISP assures me that the mod_rewrite module is available, and that I can use it from an .htaccess file in my directory.

    Here are the data, and what I am trying to do; I hope someone can tell me exactly how to do it.

    The actual address of the directory in which the top-level files for the site exist is:

    /usr/home/ewalker/public_html/validsff

    The directory in which the php file at issue resides is one down:

    /usr/home/ewalker/public_html/validsff/PHP

    The URL that is directed into the top-level directory is:
    SEMrush
    http://greatsfandf.com

    What I want to do is to transform a call that looks like this:

    http://greatsfandf.com/XX/yyyyyyyyyy.html

    (where XX is one of six possible two-letter upper-case alphabetic codes, and yyyyyyyyyy is a ten-character upper-case alphanumeric code) into this call:

    http://greatsfandf.com/PHP/
    onebook.php?natl=zzzzzz&asin=yyyyyyyyyy

    [line split to fit screen]

    (where zzzzzz is some text uniquely determined by the value of XX).

    I assume I will want six rules, one for each posible value of XX.

    I have tried various permutations of text in the .htaccess file, but none have produced anything but a 500 error. The last lines I tried--using "UK" for XX and what you see below for zzzzz--looked like this:

    RewriteEngine on
    Rewrite Base /usr/home/ewalker/public_html/validsff
    Rewrite Rule ^/UK/[A-Z0-9]{10}.html$ validsff/PHP/onebook.php?myid=greatsciencfi-21&asin=$2

    My guess is that the problem lies in the Base, but I also do not quite understand the caret ^ character, which some articles show and some don't and none explain; nor am I sure if I want $1 or $2.

    Help, please?
     
    Owlcroft, Mar 23, 2004 IP
    SEMrush
  2. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,297
    Likes Received:
    2,602
    Best Answers:
    461
    Trophy Points:
    710
    Digital Goods:
    29
    #2
    Try this:


    
    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteBase /
        RewriteRule ^X1/([a-zA-Z0-9]+)\.html$    /PHP/onebook.php?natl=Y1&asin=$1 [L]
        RewriteRule ^X2/([a-zA-Z0-9]+)\.html$    /PHP/onebook.php?natl=Y2&asin=$1 [L]
        RewriteRule ^X3/([a-zA-Z0-9]+)\.html$    /PHP/onebook.php?natl=Y3&asin=$1 [L]
        RewriteRule ^X4/([a-zA-Z0-9]+)\.html$    /PHP/onebook.php?natl=Y4&asin=$1 [L]
        RewriteRule ^X5/([a-zA-Z0-9]+)\.html$    /PHP/onebook.php?natl=Y5&asin=$1 [L]
        RewriteRule ^X6/([0-9]+)\.html$    /PHP/onebook.php?natl=Y6&asin=$1 [L]
    </IfModule>
    Code (markup):
    Where Y1 corresponds to the lookup of X1. If asin is unique, could you query it like so?...

    
    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteBase /
        RewriteRule ^([a-zA-Z0-9]+)/([a-zA-Z0-9]+)\.html$    /PHP/onebook.php?asin=$2
    </IfModule>
    Code (markup):
    Then you could have the 2 digits be anything...

    - Shawn
     
    digitalpoint, Mar 23, 2004 IP
  3. Owlcroft

    Owlcroft Peon

    Messages:
    645
    Likes Received:
    34
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thank you, thank you! Works like a prince.

    The ASIN is not unique. With Amazon, for books the ASIN is identical to the ISBN, but more than one national Amazon division--the Xn code signifies a given Amazon national division: I could have used some arbitrary single character, but it's more pleasant to have the code meaningful, as with DE or US--can carry a given edition.

    Now, one last thought:: if I make almost 7000 of those pseudo-pages, is my ISP likely to get steamed at the hammering the searchbot will probably be handing out as it tries to slurp them up?

    I have, at my level of operation, never before given the least thought to my ISP's constraints, but I see that my account type gets 500 MB/day, of which--with this and several other sites, one moderately busy one which is seasonally inactive at present--I am using, it appears, about 110 to 115 a day average. Well, I suppose I might as well just try it and see. . . .

    Thanks again.
     
    Owlcroft, Mar 23, 2004 IP
  4. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,297
    Likes Received:
    2,602
    Best Answers:
    461
    Trophy Points:
    710
    Digital Goods:
    29
    #4
    I doubt your spider traffic will skyrocket too much. It's not like they will spider it daily... So unless your ISP is REALLY anal, I think you would be fine.

    - Shawn
     
    digitalpoint, Mar 23, 2004 IP
  5. Owlcroft

    Owlcroft Peon

    Messages:
    645
    Likes Received:
    34
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Well, at least I will be reminded to check all those neat graphs and such that are provided me.

    As a sidebar: it occurred to me that there is another way to deal with the matter; it is somewhat less efficient, but would work. That alternative is to create one real shtml file for each pseudo-page, then make that pseudo-page simply an shtml virtual include of the php file, with appropriate parameters. I was quite surprised to find that a php file could be included by shtml as its virtual include, but I tried it and it worked. (I realize now that I didn't try it with passed parameters in the virtual-include URL, but I'd bet that works too.)

    Remarkable the odd things one discovers when playing about. (OK, OK, I suppose everyone else has always known that: but it was news to me.)

    Let's see how quickly Google sees my extra new 6812 pages, and what they do to my serp. . . .
     
    Owlcroft, Mar 23, 2004 IP