Simple htaccess mod_rewrite question

Discussion in 'Apache' started by Optional, Oct 8, 2008.

  1. #1
    Optional, Oct 8, 2008 IP
  2. seismic2

    seismic2 Peon

    Messages:
    27
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Here you go :
    RewriteRule ^search\.php\?q=([^/\.]+)$ /cgi-bin/search.cgi?query=$1 [R=301,L]
    
    Code (markup):
    It produces a 301 Permanently Moved response too.
     
    seismic2, Oct 8, 2008 IP
  3. Optional

    Optional Peon

    Messages:
    123
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thankyou, but it doesn't seem to be working for me.

    Here is what I have in there;

    
    Options +FollowSymLinks
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^www.domain\.com$ [NC]
    RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]
    RewriteRule ^search\.php\?q=([^/\.]+)$ /cgi-bin/search.cgi?query=$1 [R=301,L]
    
    
    Code (markup):
     
    Optional, Oct 8, 2008 IP
  4. seismic2

    seismic2 Peon

    Messages:
    27
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Oh, I forgot that RewriteRule doesn't look at the query string. Here you go :
    RewriteCond %{QUERY_STRING} ^q=([^/\.]+)$
    RewriteRule ^search\.php /cgi-bin/search.cgi?query=%1 [R=301,L]
    Code (markup):
     
    seismic2, Oct 11, 2008 IP
  5. Optional

    Optional Peon

    Messages:
    123
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks for trying again, but I managed to get it sorted out using another method.

    I found out that rewrite rules don't work with cgi-bin URLs on most hosts... as the cgi-bin isn't below the htdocs folder.

    I ended up creating a file search.php and just put this in it;

    header("Location: http://domain.com/cgi-bin/search.cgi?query=$q",TRUE,301);
     
    Optional, Oct 11, 2008 IP
  6. seismic2

    seismic2 Peon

    Messages:
    27
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    The above mod_rewrite solution should've worked too.(I'd encourage you to try it).

    But I'm glad you've been able to solve it by yourself.
     
    seismic2, Oct 11, 2008 IP