Bizarre 301 redirect issues

So here is one that has me stumped. I’m trying to redirect posts from an old forum that I’ve converted from phpbb to vbulletin. In the .htaccess file, I’ve put in the following:

Redirect 301 /viewtopic.php?f=11&t=12 [noparse]http://www.new.com/forum/showthread.php?t=23344[/noparse]

That doesn’t do a thing. If you go to http://www.old.com/viewtopic.php?f=11&t=12 , it simply shows the post on the old site. Now if I enter:

Redirect 301 / [noparse]http://www.new.com/forum/[/noparse]

That will redirect the root directory to the forum directory on the new site properly. What I can’t get are the individual pages to work. If I enter the following:

Redirect 301 / [noparse]http://www.new.com/forum/[/noparse]
Redirect 301 /viewtopic.php?f=11&t=12 [noparse]http://www.new.com/forum/showthread.php?t=23344[/noparse]

I get page not found errors because the server is looking at the root based redirect and sending me to the new site with the old extension

[noparse]http://www.old.com/viewtopic.php?f=11&t=12[/noparse]

That obviously doesn’t exist. Has anyone ever seen a case where redirect is ignoring individual pages?

IIRC you can’t use the query string in Redirect, only complete path URLs.

If you want to redirect using values in the query string you should use mod_rewrite instead


RewriteEngine On
RewriteCond %{QUERY_STRING} f=11&t=12
RewriteRule ^viewtopic.php http://www.new.com/forum/showthread.php?t=23344 [L,R=301]

HTH :slight_smile:

Thanks - it doesn’t work - and as if it couldn’t get weirder.

In Firefox, Safari and IE it just stays on the old site as if nothing is rewritten. Nothing happens.
But when I go to Chrome, I get sent to http://www.new.com/forum/viewtopic.php?f=13&t=18

Before you test it, please make sure to empty the cache of your browser and restart it. Browsers cache 301 redirects, so if they have an old redirect stored somewhere they will use that instead of the new one.

While testing it’s better to use 302 redirected (which should not be cached browsers) and then switch to 301 once you’ve established it works.

I’ve just tested the code I showed you, and it works fine here. Could you please post your complete .htaccess?

Also, which version of Apache are you on, 1.x or 2.x ?

Many thanks!!!

For reasons I cannot explain, after about 2 minutes, whatever it was that was causing the problem just stopped and using your suggestion works although the standard does not.

Perhaps it was the browser cache? Hard to say because I thought I had IE as autoemptying. Another good one to know after much frustration. Again, many thanks!!

One last question if I may - the only thing not redirecting now is the root - I tried doing just a rewrite rule with either /index.php or just a / and neither worked. Is there anything you can suggest that would complement the above for this? (I’ve actually just purchased the hardcover mod rewrite book just now :slight_smile: )

Where should they redirect to? Also, please show the code you wrote :slight_smile:

Thanks. :slight_smile:

root directory should go to http://www.new.com/forum/

I tried
RewriteRule ^/ http://www.thelaw.com/forums/ [R=301,L]
RewriteRule ^/index\.php http://www.thelaw.com/forums/ [R=301,L]

and neither worked. The root evidently has both old.com/ and old.com/index.php url to refer to home.

Again, many thanks!

RewriteRules don’t start with a tailing slash (at least, not anymore in Apache 2.x, they used to in 1.x)

So instead of ^/ it should be ^$ (i.e. empty request, i.e., root), and ^/index\.php should be ^index\.php

:slight_smile:

Note: The Redirect statements did not work because (I believe) mod_alias can’t look at the query string. That’s why Rémon recommended mod_rewrite, the Swiss Army Knife for webmasters.

Regards,

DK