mod rewrite causes 500 internal server error

Discussion in 'Apache' started by andre75, May 12, 2007.

  1. #1
    
    RewriteCond %{query_string} ^(page=[0-9]+?)&from=[0-9]+?$
    RewriteRule ^(.*)$ http://www.mysite.com/$1?%1 [R=301,L]
    
    Code (markup):
    Whats wrong with this rewire rule?
    I basically want to rewrite:

    
    somesite.com/node?page=4&from=75
    
    Code (markup):
    to

    
    somesite.com/node?page=4
    
    Code (markup):
    Thanks for your help.
     
    andre75, May 12, 2007 IP
  2. inworx

    inworx Peon

    Messages:
    4,860
    Likes Received:
    201
    Best Answers:
    0
    Trophy Points:
    0
    #2
    It can be due to PHPsuEXEC as well. Did you recently updated your Apache without php suexec support to papache with php suexec support?
     
    inworx, May 13, 2007 IP
  3. andre75

    andre75 Peon

    Messages:
    1,203
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I was thinking about it, but I haven't done it (too much of a hassle).
    Could you elaborate a little further though? I am a bit confused why this would have any impact on mod rewrite?
     
    andre75, May 14, 2007 IP
  4. tespio

    tespio Peon

    Messages:
    16
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Or maybe mod_rewrite module is just no loaded into Apache. Check your httpd.conf or apache2.conf(as is the case) if the mod_rewrite is loaded and restart apache. For non-debian systems mod_rewrite is Loaded from httpd.conf. For debian systems mod_rewrite needs to be loaded by executing a2endmod rewrite. If it's a windows system it is also loaded form httpd.conf.

    Regards
    Andy
     
    tespio, May 15, 2007 IP
  5. ajsa52

    ajsa52 Well-Known Member

    Messages:
    3,426
    Likes Received:
    125
    Best Answers:
    0
    Trophy Points:
    160
    #5
    Maybe you need to add this line "RewriteEngine on" just above of your RewriteCond line ?

    To detect the offending line, try removing one by one until the error dissapears. Then try adding that line with a basic syntax, and then step by step until that error appears again.
     
    ajsa52, May 15, 2007 IP
  6. andre75

    andre75 Peon

    Messages:
    1,203
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Thanks for the suggestions, here is a bit more information:
    Mod rewrite is installed, this is not the only rewrite I have in my .htaccess and all others work just fine.
    RewriteEngine on is there too, as I said I have multiple rewrites that work beautifully, so that can't be it.
    I posted the two offending lines, I commented them out and everything works, I put them back and it breaks. I don't want to comment out only one of them, since they depend on each other.

    Any other suggestions? Does anyone see anything wrong with this?
     
    andre75, May 15, 2007 IP
  7. ajsa52

    ajsa52 Well-Known Member

    Messages:
    3,426
    Likes Received:
    125
    Best Answers:
    0
    Trophy Points:
    160
    #7
    I'm not sure but I think you need to put %{QUERY_STRING} uppercase instead of %{query_string}
     
    ajsa52, May 15, 2007 IP
    andre75 likes this.
  8. lemaitre

    lemaitre Peon

    Messages:
    61
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #8
    I have seen query string tests like this cause infinite loops though I am not sure why. Using an alternate approach has fixed it for me:

    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /node\?(page=[^&]+)&from=([^\ ]+)\ HTTP/
    RewriteRule ^(.*)$ http://www.mysite.com/$1?%1 [R=301,L]
    Code (markup):
    See if that works for you.
     
    lemaitre, May 16, 2007 IP
    andre75 likes this.
  9. andre75

    andre75 Peon

    Messages:
    1,203
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Thanks guys. I will most defenitely try the last two suggestions (green is coming your way).
     
    andre75, May 16, 2007 IP