I need help setting up a redirect so all our old topic links can point to their new homes. The old format was:
dreamviews.com/forum/viewtopic.php?t=#####
new forum:
dreamviews.com/forum/index.php?showtopic=#####
Everything I've tried using RedirectMatch has not worked.![]()
Each new day is a chance to turn it all around.
Yeah, I've been trying to get Apache listening to my fantastically perfect regex for like the last half hour (pratically just like yours) but for some reason it isn't doing the redirection properly. It just ignores the rules I've set out:
It's okay when I remove the ?t= part, which is basically useless. And no, apparently I didn't need to escape the period even though it's a regex symbol. I tried it both with and without escaping and it didn't care. Whenever I try using the vodoo that is mod_rewrite I always find a million things not working quite how I expect. I think I blame Apache.Code:RewriteEngine on RewriteRule ^forum/viewtopic\.php\?t=([0-9]+) forum/index.php?showtopic=$1 [R]
It might just be better to make a viewtopic.php:
Same result, less heartache!Code:<?php header ( "Location: http://www.dreamviews.com/forum/index.php?showtopic=" . $_GET [ 't' ] ); die ( "This is an old forum link. You are now being redirected to the topic on the new forums." ); ?>
visual example of it at work
![]()
(\_ _/)
(='.'=)
(")_(")
I thought exactly the same thing. Regex Coach does the same here. Try it on Apache though. It doesn't work.
I think mine (my Apache installation) is screwed. It should damn work. I think maybe my installation (possibly others I guess) bork out with the "?" character and anything beyond that. I've wrote a million mod_rewrite rules before, but they were all folder names going to PHP files with the query.
Heh yeah. Not that you can copy and paste from the picture though.
EDIT: In the picture, what was with the regex code, namely the (12345) part? That should be [0-9]+. Not that I've used Regex Coach's replace tab before so I have no idea.
I know! You'd think so, but it doesn't care on my installation. Like I said, I think something is so whored out. Or I don't know so much about the start/end anchors as I should. The code will probably work on the server here and I'll look like a wannabe trying to protect his status of fantastically perfect Regex maker.
EDIT: Yeah. When I use this Regex code:
It'll redirect to that topic 3 just fine. Even though there's the start anchor. But redirecting constantly to topic three is totally useless (unless it's a topic full of naked women), so I add in the regex to capture the integer:Code:RewriteRule ^forum/viewtopic\.php forum/index.php?showtopic=3
And, whammo, no more redirection for me. Just a "viewtopic.php could not be found", you know, because it isn't redirecting for crap. I must have enabled "WhoreOutRegex" in http.conf.Code:RewriteRule ^forum/viewtopic\.php\?t=([0-9]+) forum/index.php?showtopic=$1![]()
it seems the query string is seperated from the base url by apache
and so the two need to treated seperately
so, could someone test this out
RewriteEngine on
RewriteCond %{QUERY_STRING} ^t=([0-9]+)
RewriteRule viewtopic.php index.php?showtopic=%1
(\_ _/)
(='.'=)
(")_(")
I thought something funny was going on. I would've got there if I had been bothered to keep going, I'm sure.
Yes, it works. Just checked it. Just shove all the /forum prefixes on ther eand it's good to go.
Yay, I win, I win !!!
(\_ _/)
(='.'=)
(")_(")
Okay. Your prize is a lifetime's supply of aniseed balls and Slimfast, the drink that lets you slim at accelerated speeds. That's right. Fast.
no need, no need
I got meself one o'these, instead
![]()
(\_ _/)
(='.'=)
(")_(")
Haha. Who the crap would wear that.
thanks guys, but i still can't get it working. i've tried:
and then each of these:Code:RewriteEngine on RewriteCond %{QUERY_STRING} ^t=([0-9]+)
so what's wrong?Code:RewriteRule /forum/viewtopic.php /forum/index.php?showtopic=%1 RewriteRule ^/forum/viewtopic.php /forum/index.php?showtopic=%1 RewriteRule viewtopic.php index.php?showtopic=%1
Each new day is a chance to turn it all around.
Could be almost anything I guess. Mod_rewrite is a can of worms! Evil worms.
So the condition isn't being triggered? Have you tried getting rid of the ^ anchor in the QUERY_STRING line? Just before t=([0-9]+). Not sure if that will help, but I don't know if an anchor should be there, so it may be worth a try.
EDIT: That said, it worked on my test server. So I technically have no idea.
in which case, I'd modify the viewtopic file, as Kaniaz said
Code:<?php if (isset($_GET['t'])) { header("Location: http://www.dreamviews.com/forum/index.php?showtopic=" . $_GET['t']); } else { header("Location: http://www.dreamviews.com/forum/index.php"); } ?>
(\_ _/)
(='.'=)
(")_(")
Alright, great. thanks both of you!
Each new day is a chance to turn it all around.
Bookmarks