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.

Mod rewrite problem HEEELP

Discussion in 'Apache' started by Thewormman, Jan 29, 2005.

  1. #1
    Hi
    I am trying to set up the free searchbox that Shawn supplies here on my site and would like to mod rewrite the URL's of the results search pages.

    I have made a .htaccess file for the directory the search results. php file is in, and have added these lines

    RewriteEngine On
    RewriteRule   bluewidgets   results.php?q=blue+widgets
    Code (markup):
    But it doesn't work, any suggestions on what I am doing wrong?

    Many thanks
     
    Thewormman, Jan 29, 2005 IP
  2. J.D.

    J.D. Peon

    Messages:
    1,198
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    0
    #2
    The pattern in RewriteRule has to cover the entire URL (minus the base path of the resource). For example:

    RewriteRule   ^bluewidgets/$   results.php?q=blue+widgets
    Code (markup):
    J.D.
     
    J.D., Jan 29, 2005 IP
  3. Thewormman

    Thewormman Peon

    Messages:
    95
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks JD

    Tried that and it still didn't work :confused:

    Any other suggestions anyone
     
    Thewormman, Jan 30, 2005 IP
  4. J.D.

    J.D. Peon

    Messages:
    1,198
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Did you have the trailing slash at the end of bluewidgets?

    J.D.
     
    J.D., Jan 30, 2005 IP
  5. Thewormman

    Thewormman Peon

    Messages:
    95
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Yep, made sure I did it exactly as you said...
     
    Thewormman, Jan 30, 2005 IP
  6. J.D.

    J.D. Peon

    Messages:
    1,198
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Sorry, I should've been more specific - that is, was there a slash when you made a test request?

    What you can do, if you have control over the server configuration, is to enable rewrite loging and see if this gives you any additional info to go on. Add these lines in your httpd.conf file (they work at the server or virtual host level; your file path may be different):

    RewriteEngine on
    RewriteLogLevel 3
    RewriteLog /usr/local/apache2/logs/rewrite_log
    Code (markup):
    J.D.
     
    J.D., Jan 30, 2005 IP
  7. Thewormman

    Thewormman Peon

    Messages:
    95
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #7
    yep laid it out the same as you put it

    Sorry you lost me there, don't think I am able to do that, I think I don't have access to that file.

    Don't know if this helps but I already have a rewrite working in another directory with it's own htaccess file, it looks like this

    RewriteEngine On
        RewriteBase /
    
        RewriteRule ^uk-1/([A-Z0-9]+)\.html$  /widgets/free1.php?asin=$1 [L]
    Code (markup):
    and works fine in that application, I didn't write this though, it came with a program I use.

    Thanks for the help BTW :)

    EDIT
    Tried that configuration which is basically the same and it didn't work either
     
    Thewormman, Jan 30, 2005 IP
  8. J.D.

    J.D. Peon

    Messages:
    1,198
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    0
    #8
    I asked because I forgot to make the slash optional, so it will work only with a slash in the request. Add a question mark after the slash in the pattern to make it optional (i.e. ^bluewidgets/?$).

    If there are other rewrite directives in this file matching bluewidgets, check if any of them have [L] (this means that it's the last rule).

    The bottom line is that it seems that this rule isn't being processed. In general, even your initial line should work, except that it will match any URL that contains the sequence of charaters bluewidgets (which is why it isn't a good idea to use it in this way; e.g. it will match /store/greatbluewidgets/).

    J.D.
     
    J.D., Jan 30, 2005 IP
  9. Thewormman

    Thewormman Peon

    Messages:
    95
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #9
    No there are no others matching "bluewidgets" and the other example I quoted is in a completely different directory with its own htaccess file.

    So why do you think the other URLs are being rewritten OK and the ones in this directory are not?

    Could one be interfering with the other?
     
    Thewormman, Jan 30, 2005 IP
  10. J.D.

    J.D. Peon

    Messages:
    1,198
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    0
    #10
    The only thing I can think of is that if you have some rule with [L] that matches bluewidgets (it doesn't have to be bluewidgets - can be just ^.*$).

    You need to make sure that rewrite rules in this particular .htaccess work (you may have some working rules that prove this, or you can add a catch-all rule at the beginning of the file, similar to the one above, and see if it is being processed).

    Once you confirmed that rewrite rules in this file are being processed, it's just down to their order/syntax.

    J.D.
     
    J.D., Jan 30, 2005 IP
  11. nevetS

    nevetS Evolving Dragon

    Messages:
    2,544
    Likes Received:
    211
    Best Answers:
    0
    Trophy Points:
    135
    #11
    if your .htaccess file is working in a different directory and not in this one...
    it's possible that the "FileInfo" override is only set in the working directory, and not in the broken one - meaning that you can do rewrites in one place but not in another.

    If the .htaccess file is working in your root directory, you can ignore this comment.

    Is this the only thing in your .htaccess file? Can you copy/paste the entire thing here (as it is now) so we can see it and try it out to help you?
     
    nevetS, Jan 30, 2005 IP
  12. Thewormman

    Thewormman Peon

    Messages:
    95
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Ok
    Did a bit of a test, moved all the files into my root directory and placed the rewrite rule in my root htaccess above all the other rules so this was the first.

    Still didn't work! but all the others did, so all I can imagine is that maybe the searchbox works through shawns servers and so bypasses my htaccess instructions.

    What do you think?
     
    Thewormman, Jan 31, 2005 IP