Boston Tent Rental - Loan - Loan - Loan - Loan

PDA

View Full Version : Mod Rewrite this url?


Infiniterb
Mar 9th 2005, 9:21 am
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).

rgeimer
Mar 9th 2005, 10:04 am
You might try the following:

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

Infiniterb
Mar 9th 2005, 10:20 am
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.

J.D.
Mar 9th 2005, 1:01 pm
Well, I screwed up a bit during my re-write of a vbulletin thread (many thanks to J.D btw).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.

Infiniterb
Mar 9th 2005, 1:12 pm
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 9th 2005, 1:29 pm
That change didn't work :(

And this is the .htaccess in the root directory, btw.

J.D.
Mar 9th 2005, 1:38 pm
That change didn't workIt 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.

Infiniterb
Mar 9th 2005, 1:53 pm
Didn't get anything.

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

Is the url I'm still getting. No 500 error or not found.

J.D.
Mar 9th 2005, 1:58 pm
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.

Infiniterb
Mar 9th 2005, 2:05 pm
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]

J.D.
Mar 9th 2005, 2:15 pm
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.

Infiniterb
Mar 9th 2005, 2:24 pm
Gonna PM you the other rewrite rules I've got...

Here we go again :)

J.D.
Mar 9th 2005, 2:25 pm
Try the rule in my last post. Let me know if it did anything.

J.D.

J.D.
Mar 9th 2005, 7:27 pm
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]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.

Infiniterb
Mar 9th 2005, 7:31 pm
And we have a winner!

Good job.