301 redirecting with a word match in URL

Discussion in 'Apache' started by angilina, Nov 23, 2008.

  1. #1
    I am trying to redirect [via .htaccess] all the URLs in my forum which will contain this,

    mode=linear

    Example URL:

    forums/showthread.php?mode=linear&tid=800&pid=1901

    I want to redirect all URLs that will have "mode=linear" in it to a 404 not found page. The reason is that this mode thing create duplication problem.

    Can someone help?
     
    angilina, Nov 23, 2008 IP
  2. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #2
    Does it have to be a 404, what about doing a 301 to the non-linear instead ?

    Something like this for starters, I'm not sure what the potential querystrings will look like, but based on what you posted this would do the trick.

    RewriteCond %{QUERY_STRING} ^mode=linear&tid=([0-9]+)&pid=([0-9]+)$
    RewriteRule showthread\.php$ showthread.php?tid=%1&pid=%2 [R=301]
    Code (markup):
     
    joebert, Nov 24, 2008 IP
  3. angilina

    angilina Notable Member

    Messages:
    7,824
    Likes Received:
    186
    Best Answers:
    0
    Trophy Points:
    260
    #3
    thanks. You are right. I have done a redirect to the non linear URL instead of 404 page.
     
    angilina, Nov 25, 2008 IP