Jump to content

  • Log in with Facebook Log in with Twitter Log In with Google      Sign In   
  • Create Account

Subscribe to HRA Now!

 



Are you a Google Analytics enthusiast?

Share and download Custom Google Analytics Reports, dashboards and advanced segments--for FREE! 

 



 

 www.CustomReportSharing.com 

From the folks who brought you High Rankings!



Photo
- - - - -

Redirecting Old Smf Forum Links To New Phbbb Ones


  • Please log in to reply
7 replies to this topic

#1 Ocipital

Ocipital

    HR 1

  • Members
  • Pip
  • 6 posts

Posted 05 October 2009 - 03:41 PM

Hey everyone,

We recently moved our decently ranking site over from a creaky old SMF forum to PHPbb (both via Joomla). I was really happy to notice that threads topic number stayed the same going across to the new forum as we have *many* old forum links in Google (even months later). Now I've been banging my head reading through a mass of overly complicated tutorials trying to figure out how to get .htaccess to rewrite:

http://mydomain.com/component/option,com_smf/Itemid,12/topic,XXXX.msgYYYY

to:

http://mydomain.com/index.php?option=com_jfusion&Itemid=18&jfile=viewtopic.php&t=XXXX

Yeah, I'm aware that the YYYY part isn't anywhere in the new URL. It doesn't seem to bother PHPbb. We're on a Linux / Apache II server with Mod_rewrite. We have some other rewrites working fine (which don't affect any of the forum URL's).


Any ideas, suggestions or links to easily understood and relevant tutorials gratefully appreciated. I've been trying to figure this out for hours!

#2 Randy

Randy

    Convert Me!

  • Moderator
  • 17,540 posts

Posted 05 October 2009 - 06:04 PM

So the Itemid is different in the two URLs then? Or is it just different in your example as a typo and they actually remain the same in each version. Or is the new forum always Itemid=18?

Assuming there are multiple Itemid's on the new forum and that's a required thing in the url, you'd first have to come up with a way to map that from the old to the new, which usually leads to a scripted redirect instead of an Apache .htaccess one. If it's a large site where a lot of it isn't the forum a scripted redirect may be the way to go anyway to hold down overhead.

#3 Ocipital

Ocipital

    HR 1

  • Members
  • Pip
  • 6 posts

Posted 05 October 2009 - 06:50 PM

Thanks Randy, ItemId is always 12 in the old url and 18 in the new one and as such they're both static and can be hardcoded. 99% of the site if the forum.

Really I'm just trying to turn:
StaticText1 $Variable1 StaticText2

into
StaticText3 $Variable1

#4 Randy

Randy

    Convert Me!

  • Moderator
  • 17,540 posts

Posted 05 October 2009 - 11:03 PM

Should be easy enough to whip you up a working example then Ocipital. Do we need to worry about the original urls already being rewritten in your .htaccess, where it might be wiser to use a {THE_REQUEST} type of rewrite condition, or is that going to be a real URL?

I'll need to tinker with it a bit to see how best to deal with the comma's in the original url string (technically that's an illegal character) but it should be doable. I'll play with it a bit tomorrow and see if I can come up with something that works on my servers. Hopefully if it works there (I have a standard Apache2 installation) it'll also work on yours.

#5 Ocipital

Ocipital

    HR 1

  • Members
  • Pip
  • 6 posts

Posted 06 October 2009 - 04:17 AM

QUOTE(Randy @ Oct 6 2009, 12:03 AM) View Post
Should be easy enough to whip you up a working example then Ocipital.

Wow. Very generous of you. Thanks!

QUOTE
Do we need to worry about the original urls already being rewritten in your .htaccess, where it might be wiser to use a {THE_REQUEST} type of rewrite condition, or is that going to be a real URL?

I wouldn't imagine so, because none of the url's being written are forum urls, so none of them should match this pattern, so I think there shouldn't be any cross rule complications.

QUOTE
I'll need to tinker with it a bit to see how best to deal with the comma's in the original url string (technically that's an illegal character) but it should be doable. I'll play with it a bit tomorrow and see if I can come up with something that works on my servers. Hopefully if it works there (I have a standard Apache2 installation) it'll also work on yours.


If you ever need a design favor, you know who to ask. smile.gif

#6 Randy

Randy

    Convert Me!

  • Moderator
  • 17,540 posts

Posted 06 October 2009 - 08:58 PM

I remember now why I hate commas so much. hysterical.gif

Actually, I don't hate commas, I just hate what the different browsers out there and even different installations of Apache do with them because they all do their encoding a little bit different. Sometimes browsers will even make the mistake of encoding the encoding, which is really, really, really a pain in the arse.

Please people, do not ever use commas in your urls if there is even the remotest chance that you may need to redirect things at a latter date. They are really a pain to deal with after the fact.

That said, here's what I have working on all of the various *nix boxes I tested it on Ocipital. And this assumes the XXXX topic stuff is all numbers. I'm doing that because this kind of thing really should be as specific as possible. If it's letters or a combination of letters and numbers let me know and I'll tweak from this starting point.

CODE
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /component/option(,|\%(25)*2C)com_smf/Itemid(,|\%(25)*2C)12/topic(,|\%(25)*2C)([0-9]+).msg(.*)\ HTTP/ [NC]
RewriteRule ^(.*)$ http://mydomain.com/index.php?option=com_jfusion&Itemid=18&jfile=viewtopic.php&t=%7 [R=301,L]


(Hopefully the forums don't mangle that too badly since they're pretty long strings There are actually only two lines there if it does force a line break. The first line starts with RewriteCond. The second line starts with RewriteRule.)

Lots going on in there.

First, I decided it would be best to use {THE_REQUEST} instead of {REQUEST_URI} to head off some additional craziness. So that means we're looking at the actual request as sent by the browser before Apache gets ahold of it.

Second the (,|\%(25)*2C) part is simply a conditional statement to look for both unencoded and encoded commas. With an extra caveat in there that it's also looking for the % character that's unencoded as it should be, but also both encoded and unencoded to account for some oddball browsers out there.

Third the ([0-9]+) is looking for a series of numbers, with no limit whether it's a 1 digit number or a 1,000 digit number, for later use. Then it also looks for the .msg that comes right after that in your original url string. FTR, though I don't recommend it if you need to open this up to any legitimate character for a url you can change the above to be simply (.*) that will wildcard it. I don't recommend it because it's not nearly specific enough, so could cause a dangerous loop situation.

Lastly, in the RewriteRule line make sure you change out "mydomain.com" to be your actual domain address. And in your original question you didn't have a www. in there, I presume by choice. So it's not in the redirect either. If you need it to be the www. address you'll want to add that too.

The %7 in the RewriteRule might look funny, but it's actually correct. Each time a set of parens is used in the RewriteCond line it's a new variable. Though it's easy to miss there are actually two each in the comma detector because there's a set around the "25" to deal with encoded %'s. So the 7th variable from the RewriteCond is the one we want. And an 8th after the .msg. We're simply discarding all but the one we want to use.

Give it a whirl and see if that works on your server. If it doesn't or needs to be tweaked let me know and also let me know if you're getting an error message in your logs.

Good luck! Hope it works on your server too!

#7 Ocipital

Ocipital

    HR 1

  • Members
  • Pip
  • 6 posts

Posted 07 October 2009 - 05:02 PM

Wow. Thanks!

Just reading the explanation is making my head swim, but I'll give it a shot and then see if I can re-read your explanation enough times to "get it".

Many thanks, and I'll let you know how we go!

#8 Randy

Randy

    Convert Me!

  • Moderator
  • 17,540 posts

Posted 07 October 2009 - 08:21 PM

If it works you don't necessarily have to get it. giggle.gif It's just a lot of REGEX gobbly gook after all.

Regular Expressions about as useless to most folks as those Physics and Botany classes I took 30 years ago in high school. Got good grades and almost enjoyed the classes because of the teacher, but never to used a single thing from either of 'em afterwards and it was all forgotten within a couple of years.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

We are now a read-only forum.
 
No new posts or registrations allowed.