Tricky 301 Redirect Help

Discussion in 'Apache' started by JonahViaKeyboard, Oct 11, 2005.

  1. #1
    This may be a cinch for some, but after a couple hours of tinkering I still can't get it.

    I want to 301 redirect

    DOMAIN/FOLDER/mt-comments.cgi?__mode=red&id=ANY

    to www.DOMAIN.com

    The tricky part is that I only want to trigger the redirect if the url contains ?__mode=red - if I trigger the redirect for any query string following mt-comments.cgi I run into other unacceptable problems.

    Thanks!
     
    JonahViaKeyboard, Oct 11, 2005 IP
  2. johnt

    johnt Peon

    Messages:
    178
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Try
    RewriteEngine on
    RewriteCond %{REQUEST_URI} ^/folder/mt-comments.cgi
    RewriteCond %{QUERY_STRING} __mode=red
    RewriteRule (.*) http://www.domain.com [R=301]
    
    Code (markup):
    cheers

    johnt
     
    johnt, Oct 12, 2005 IP
    JonahViaKeyboard likes this.
  3. JonahViaKeyboard

    JonahViaKeyboard Peon

    Messages:
    174
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thank you so much Johnt!! The redirect works under the right conditions and doesn't interfere with mt-comments.cgi functionality.

    One last question: once the redirect happens, the URL looks like this:
    www.DOMAIN.com/?__mode=red&id=ANY

    Is there a way to strip off the ?__mode=red&id=ANY
    Thanks!
     
    JonahViaKeyboard, Oct 12, 2005 IP
  4. johnt

    johnt Peon

    Messages:
    178
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #4
    If you want to get rid of the entire query string after a redirect you can use ? after the url you are redirecting to, i.e.
    RewriteEngine on
    RewriteCond %{REQUEST_URI} ^/folder/mt-comments.cgi
    RewriteCond %{QUERY_STRING} __mode=red
    RewriteRule (.*) http://www.domain.com/? [R=301]
    Code (markup):
    If you need to keep other aspects of the query string but just remove that one parameter / value pair, I'm not sure if you can do that. However, in this instance I think that the above is what you're after.

    cheers

    johnt
     
    johnt, Oct 13, 2005 IP
  5. JonahViaKeyboard

    JonahViaKeyboard Peon

    Messages:
    174
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Perfect, thanks so much!
     
    JonahViaKeyboard, Oct 13, 2005 IP
  6. matthintze

    matthintze Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Will that work for individual pages pointed to different URL'S, or does it only work for one domain to another?
     
    matthintze, Feb 23, 2012 IP
  7. mada0o

    mada0o Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    thanks so much
     
    mada0o, Mar 4, 2012 IP