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.

htaccess rewrite problem

Discussion in 'Apache' started by BrianR2, May 21, 2009.

  1. #1
    Hi,

    I am having trouble with a rewrite rule. I want to remove a certain query string "page=1&sort=featured" from any url on the site and I can't seem to get it working. This is the best I have come up with:

    
    RewriteCond %{QUERY_STRING} ^page=1&sort=featured$
    RewriteRule ^([^\?]+)\?(.+)$ /$1 [R=301,L]
    
    Code (markup):
    I have been working on this all day and can't get it working. Please help.
    Thanks.
     
    BrianR2, May 21, 2009 IP
  2. BrianR2

    BrianR2 Guest

    Messages:
    734
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    0
    #2
    If I do this:
    
    RewriteCond %{QUERY_STRING} ^page=1&sort=featured$
    RewriteRule (.*) http://ip_address/$1? [R=301,L]
    
    Code (markup):
    then the page http://ip_address/dir1/dir2/?page=1&sort=featured redirects to http://ip_address/index.php/dir2/. So it removes the query string but instead of "/dir1" being in there it's "index.php" for some reason. Higher up in the code there is:
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . index.php
    
    Code (markup):
    and I'm not sure if that is causing the index.php to go in there. It's kind of confusing that the (.*) doesn't match the entire url and only matches "/dir2" apparently. There is no RewriteBase defined and ip_address is because this is a dev environment.
     
    BrianR2, May 22, 2009 IP
  3. Lpe04

    Lpe04 Peon

    Messages:
    579
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #3
    It's a little confusing what you are trying to do. Can you start from scratch explaining your problem? Thanks.
     
    Lpe04, May 23, 2009 IP
  4. BrianR2

    BrianR2 Guest

    Messages:
    734
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Hi. I gave up on htaccess and did it in php and it's working. Thanks.
     
    BrianR2, May 25, 2009 IP
  5. Lpe04

    Lpe04 Peon

    Messages:
    579
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #5
    cool, glad to see it is working
     
    Lpe04, May 25, 2009 IP