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.

Mod Rewrite this url?

Discussion in 'Apache' started by Infiniterb, Mar 9, 2005.

  1. #1
    Well, I screwed up a bit during my re-write of a vbulletin thread (many thanks to J.D btw). Google indexed (and cached) my page as:

    http://www.clantt.com/carinsurance/?t=6740

    Now, normally, this wouldn't be too bad since my ranking is high and my vistors can see the content. However, the adsense ads are all screwy at this specific url. When it's re-written to the URL below, the adsense ads come up as they should and everything is fine.

    I need to mod-rewrite that to:

    http://www.clantt.com/carinsurance/

    I've tried:

    RewriteEngine On
    RewriteRule ^carinsurance/\?t=6740$ /carinsurance/ [R=301, L] - gives a 500 Internal server error.

    On the htaccess file in my root. I've also tried modifications of that in the car insurance directory such as:

    RewriteEngine On
    RewriteRule ^\?t=6740$ [R=301, L]

    Which also didn't work. I've also tried

    RewriteEngine On
    RewriteRule ^carinsurance/?t=6740$ /carinsurance/ [R=301, L]

    Still gives a 500.

    I've also tried:

    redirect 301 /carinsurance/?t=6740 http://www.clantt.com/carinsurance/

    And still no go.

    Edit: Edited the redirect 301 line to put what I did try (typed this a bit rushed just before I headed off to work).
     
    Infiniterb, Mar 9, 2005 IP
  2. rgeimer

    rgeimer Guest

    Messages:
    41
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You might try the following:

    redirect 301 /carinsurance/?t=6740 http://www.clantt.com/carinsurance/
     
    rgeimer, Mar 9, 2005 IP
  3. Infiniterb

    Infiniterb Well-Known Member

    Messages:
    1,314
    Likes Received:
    50
    Best Answers:
    0
    Trophy Points:
    168
    #3
    Thanks for the reply.

    I actually did try that. My last 301 redirect line was typed wrong (was a bit rushed when I made this post just before I headed off to work). I've edited the original post.

    I've read somewhere that different versions treat the ? operator differently when trying to redirect it. Placing a \ before that character should take care of the redirect, at least I presume that's the way it should work.
     
    Infiniterb, Mar 9, 2005 IP
  4. J.D.

    J.D. Peon

    Messages:
    1,198
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Sounds like you're thanking me for helping you to screw up a bit :D

    RewriteRule ^\?t=6740$ [R=301, L]

    Won't work; will look for this URL: ?t=6740

    Redirect isn't for this case. Use redirect when you need to match the beginning of the URL path and change the matched part to another path.

    As far as your question goes, as an quick test, try changing it to

    RewriteRule ^carinsurance/\?t=6740$ /carinsurance_/ [R=301,L]

    Test it and change it quickly back before anybody picks up this URL. Let me know if it worked this way.

    J.D.
     
    J.D., Mar 9, 2005 IP
  5. Infiniterb

    Infiniterb Well-Known Member

    Messages:
    1,314
    Likes Received:
    50
    Best Answers:
    0
    Trophy Points:
    168
    #5
    Haha, no JD, didn't mean to thank you for messing me up. I messed myself up learning the intricatcies of Mod Rewriting. But, that's how we learn this stuff I guess, trial and error.

    I'll give your suggestion a shot.

    -Richard
     
    Infiniterb, Mar 9, 2005 IP
  6. Infiniterb

    Infiniterb Well-Known Member

    Messages:
    1,314
    Likes Received:
    50
    Best Answers:
    0
    Trophy Points:
    168
    #6
    That change didn't work :(

    And this is the .htaccess in the root directory, btw.
     
    Infiniterb, Mar 9, 2005 IP
  7. J.D.

    J.D. Peon

    Messages:
    1,198
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    0
    #7
    It was not supposed to fix the problem. It was a test. Did you still get 500 or you got a "not found" error?

    J.D.
     
    J.D., Mar 9, 2005 IP
  8. Infiniterb

    Infiniterb Well-Known Member

    Messages:
    1,314
    Likes Received:
    50
    Best Answers:
    0
    Trophy Points:
    168
    #8
    Infiniterb, Mar 9, 2005 IP
  9. J.D.

    J.D. Peon

    Messages:
    1,198
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Are you saying that

    RewriteRule ^carinsurance/\?t=6740$ /carinsurance_/ [R=301,L]

    with the underscore is in .htaccess in the root directory right now? Do you get 500 when you remove the underscore?

    J.D.
     
    J.D., Mar 9, 2005 IP
  10. Infiniterb

    Infiniterb Well-Known Member

    Messages:
    1,314
    Likes Received:
    50
    Best Answers:
    0
    Trophy Points:
    168
    #10
    I'm not getting a 500 with or without the _ right now (I was this morning, now I'm not...strange).

    Currently it's in the .htaccess as follows:

    RewriteRule ^carinsurance/\?t=6740$ /carinsurance/ [R=301,L]
     
    Infiniterb, Mar 9, 2005 IP
  11. J.D.

    J.D. Peon

    Messages:
    1,198
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Could it be that you have /carinsurance/ rule somewhere else and it gets executed before this one?

    Also, try this:

    RewriteRule ^carinsurance/.*\?t=6740$ /carinsurance/ [R=301,L]

    J.D.
     
    J.D., Mar 9, 2005 IP
  12. Infiniterb

    Infiniterb Well-Known Member

    Messages:
    1,314
    Likes Received:
    50
    Best Answers:
    0
    Trophy Points:
    168
    #12
    Gonna PM you the other rewrite rules I've got...

    Here we go again :)
     
    Infiniterb, Mar 9, 2005 IP
  13. J.D.

    J.D. Peon

    Messages:
    1,198
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    0
    #13
    Try the rule in my last post. Let me know if it did anything.

    J.D.
     
    J.D., Mar 9, 2005 IP
  14. J.D.

    J.D. Peon

    Messages:
    1,198
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    0
    #14
    I completely forgot that query strings are not supposed to be used in rewrite rules. Here's the working version:
    RewriteCond %{QUERY_STRING} ^t=6740$
    RewriteRule ^carinsurance/$ /carinsurance/? [R=301,L]
    Code (markup):
    The question mark at the end of the substitution removes all query string arguments (it will not appear in the resulting URL). If omitted, the text after the ? in the original URL will be appended to the substitution.

    J.D.
     
    J.D., Mar 9, 2005 IP
    Infiniterb likes this.
  15. Infiniterb

    Infiniterb Well-Known Member

    Messages:
    1,314
    Likes Received:
    50
    Best Answers:
    0
    Trophy Points:
    168
    #15
    And we have a winner!

    Good job.
     
    Infiniterb, Mar 9, 2005 IP