Need some mod_rewrite assistance

Discussion in 'Apache' started by Muschnick, Nov 3, 2009.

  1. #1
    Hi,

    Thanks in advance for your help....

    I am beginner with mod_rewrite(among other things) and I can't seem to get it to work. My site is built with phpprobid(.com). My site is hosted on 1and1.com and the reason I mention that is it may have something to do with my troubles.

    My site is www.rutscameras.com

    Here is what I have in my .htaccess file and I am still getting multiple links with 404 errors:

    --------

    RewriteEngine On
    RewriteRule ^(.*),(.*)$ $2.php?rewrite_params=$1&page_url=$2

    RewriteCond %{QUERY_STRING} base64_encode.*(.*) [OR]
    RewriteCond %{QUERY_STRING} (<|%3C).*script.*(>|%3E) [NC,OR]
    RewriteCond %{QUERY_STRING} GLOBALS(=|[|%[0-9A-Z]{0,2}) [OR]
    RewriteCond %{QUERY_STRING} _REQUEST(=|[|%[0-9A-Z]{0,2})
    RewriteRule ^(.*)$ index.php [F,L]

    Any help you can offer is greatly appreciated! If you need more info let me know and I will answer anything I can.

    Thanks!
     
    Muschnick, Nov 3, 2009 IP
  2. chadsmith

    chadsmith Peon

    Messages:
    82
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #2
    What are some links you're getting 404s on?

    The htaccess file doesn't do much but tell links such as

    yoursite.com/hello,there to go to yoursite.com/there.php?rewrite_params=hello&page_url=there

    The last part blocks access (403 Forbidden) when queries include base64_encode, <script>, GLOBALS= and _REQUEST= parameters to avoid injection and XSS attempts.
     
    chadsmith, Nov 3, 2009 IP
  3. Muschnick

    Muschnick Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Here are some of the links I get the 404 error.

    mod_rewrite enabled, 404 Error:
    http://www.rutscameras.com/new_item,option,sell_item
    mod_rewrite disabled, works fine:
    http://www.rutscameras.com/sell_item.php?option=new_item


    mod_rewrite enabled, 404 Error:
    http://www.rutscameras.com/help,page,content_pages
    mod_rewrite disabled, works fine:
    http://www.rutscameras.com/content_pages.php?page=help


    mod_rewrite enabled, 404 Error:
    http://www.rutscameras.com/faq,page,content_pages
    mod_rewrite disabled, works fine:
    http://www.rutscameras.com/content_pages.php?page=faq

    Thanks for taking a look at this!
     
    Muschnick, Nov 3, 2009 IP
  4. chadsmith

    chadsmith Peon

    Messages:
    82
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #4
    It looks like you're missing a rule then:

    RewriteRule ^(.*),(.*),(.*)$ $3.php?$2=$1
    Code (markup):
     
    chadsmith, Nov 3, 2009 IP
  5. Muschnick

    Muschnick Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Does it matter where in the htaccess your rule is listed?
     
    Muschnick, Nov 3, 2009 IP
  6. Muschnick

    Muschnick Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    It doesn't appear to have changed anything. I am still running into the same 404 errors on the same links.

    Maybe I put it in the wrong spot in the htaccess file? Does that matter?


    Thanks again!
     
    Muschnick, Nov 3, 2009 IP
  7. chadsmith

    chadsmith Peon

    Messages:
    82
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Put it above the first rule
     
    chadsmith, Nov 3, 2009 IP
  8. Muschnick

    Muschnick Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Unfortunately I am still getting the same results with the following as the htaccess file:

    Options -Multiviews

    RewriteEngine On
    RewriteRule ^(.*),(.*),(.*)$ $3.php?$2=$1
    RewriteRule ^(.*),(.*)$ $2.php?rewrite_params=$1&page_url=$2

    RewriteCond %{QUERY_STRING} base64_encode.*(.*) [OR]
    RewriteCond %{QUERY_STRING} (<|%3C).*script.*(>|%3E) [NC,OR]
    RewriteCond %{QUERY_STRING} GLOBALS(=|[|%[0-9A-Z]{0,2}) [OR]
    RewriteCond %{QUERY_STRING} _REQUEST(=|[|%[0-9A-Z]{0,2})
    RewriteRule ^(.*)$ index.php [F,L]
     
    Muschnick, Nov 3, 2009 IP
  9. Muschnick

    Muschnick Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Could it have something to do with using 1and1 for hosting? I have heard rumblings about issues with mod_rewrite while using 1and1. I have found a few items you will understand better than I will. Please let me know what you think.....

    I just found these dicussions(sorry for the spaces after the http:// but I can't post links yet....

    http:// forums.digitalpoint.com/showthread.php?t=893009 :

    One and One doesn't allow PHP short tags. I've used them for quite a while and I haven't had short tags work at all.

    You have to go the extra 3-letters milehttp:// forum.cmsmadesimple.org/index.php?topic=8550.0 :

    FYI...1and1 hosting shared Linux accounts work great as an alternative. All that needs to be done there is simply switching the pretty URL switch in config.php to true and you get decent urls (albeit with no extensions) on all pages including news items.
     
    Muschnick, Nov 3, 2009 IP
  10. Muschnick

    Muschnick Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Ahhhhhhhh!

    I figured it out although I have no idea what I really did.....

    I found a thread in a different forum that said you need to add the following into the .htaccess to get mod_rewrite to work if you use 1and1 hosting. I have no idea what they do to require this but it works

    RewriteBase /

    --------

    Options -Multiviews

    RewriteEngine On
    RewriteBase /
    RewriteRule ^(.*),(.*)$ $2.php?rewrite_params=$1&page_url=$2

    RewriteCond %{QUERY_STRING} base64_encode.*(.*) [OR]
    RewriteCond %{QUERY_STRING} (<|%3C).*script.*(>|%3E) [NC,OR]
    RewriteCond %{QUERY_STRING} GLOBALS(=|[|%[0-9A-Z]{0,2}) [OR]
    RewriteCond %{QUERY_STRING} _REQUEST(=|[|%[0-9A-Z]{0,2})
    RewriteRule ^(.*)$ index.php [F,L]


    Thanks for your help Chad!
     
    Muschnick, Nov 3, 2009 IP