View Full Version : 301 / 404 script - dvermeul
dvermeul
Wed 16th Aug '06, 11:03am
I use a special URL scheme for my phpBB forum. URLs look like /article#####.html, where ##### is the topic ID. Of course, after using Impex, vBulletin's topic ID is different. But since the import IDs are still there, it should be able to find the new topic ID and redirect the visitor properly. My only concern is: can it parse article#####.html?
Hi Jerry,
I am using more or less the same system: I have a phpbb forum with the able2know seo mod from Craven de Kere (http://www.able2know.com/forums/about15132.html). My current phpbb forum is very well indexed in Google; about 37.000 pages. I would like to create a 301 redirect for all those indexed pages, so that visitors for:
www.mydomain.nl/viewtopic.php?t=1234 (http://www.mydomain.nl/viewtopic.php?t=1234)
and
www.mydomain.nl/about1234.html (http://www.mydomain.nl/about1234.html)
are redirected to
www.mydomain.nl/showthread.php?t=5678 (http://www.mydomain.nl/showthread.php?t=5678)
What would be the best way for me to adapt your 404.php script to accept also the /about1234.html urls that are indexed in Google?
Thanks for any help you can give me.
Regards,
Daniel
PS: I am was not planning on leaving my old phpbb forum running as a reference like gengar56
Edit: Just thought of this: I am even allowed to edit your script for my own use?
Jerry
Wed 16th Aug '06, 3:10pm
Edit: Just thought of this: I am even allowed to edit your script for my own use?
It's a tool I wrote to help, you can do what you want with it to suit your needs, as long as you let me know what it is, then I can update and evolve the script to help others :) As more people ask for the different URL combinations, I'll upgrade and redesign the script to get more and more.
What would be the best way for me to adapt your 404.php script to accept also the /about1234.html urls that are indexed in Google?
I take it the aboutXXXX.html is constant to the importthreadid ?
I would add this just after the thread link section on line 113 :
if (strpos($_SERVER['REQUEST_URI'], "/{$old_folder}/about") === 0)
{
if(preg_match('#(.*)about(.*).html#Uis', $_SERVER['REDIRECT_QUERY_STRING'], $matches))
{
if (is_int($matches[2]))
{
$action = 'thread';
$sql = "SELECT threadid FROM {$tableprefix}thread WHERE importthreadid=" . $matches[2];
}
}
}
Then it will match the "about" to the thread look up.
dvermeul
Thu 17th Aug '06, 4:51am
Wow, thanks for the excellent support, Jerry! I was already looking into adding a piece of code to take care of the /aboutxxxx.html, but I couldn't figure it out...
Thanks again,
Daniel
dvermeul
Thu 17th Aug '06, 12:41pm
Hey Jerry,
I started looking a little closer at the above code and I have a few questions, if you don't mind.
Could it be that this
if (strpos($_SERVER['REQUEST_URI'], "/{$old_folder}/about")) should be
if (strpos($_SERVER['REQUEST_URI'], "/{$old_folder}/about")) === 0
I also looked at the regular expression a little closer and I couldn't figure it all out. Wouldn't this be sufficient:
about(.*).html I tested it with a regular expression editor (http://www.waterproof.fr/products/RegExpEditor/) and this showed that $matches[2] would contain the phpbb threadid. But I have to admit though that I don't know what the $_SERVER['REDIRECT_QUERY_STRING'] displays (ie. full url or part of an url or something else), so that could make the regexp more complex...
Jerry
Thu 17th Aug '06, 1:34pm
Oh yea, it should have the "=== 0" though apart from that it should work fine, the regex, works on the URL's I tested.
dvermeul
Thu 17th Aug '06, 7:37pm
Thanks for your reply, Jerry.
Sorry for being such a pain in the behind, but I ran another small test:
<?php
$subject = "http://www.mydomain.nl/about12345.html";
$pattern = '#(.*)about=(.*).html#Uis';
preg_match($pattern, $subject, $matches);
print_r($matches);
?>
This doesn't return anything while:
<?php
$subject = "http://www.mydomain.nl/about12345.html";
$pattern = '#(.*)about(.*).html#Uis';
preg_match($pattern, $subject, $matches);
print_r($matches);
?>
delivers the correct result:
Array ([0] => http://www.mydomain.nl/about12345.html [1] => http://www.mydomain.nl/ [2] => 12345 )Shouldn't the '=' be left out?
dvermeul
Sun 10th Sep '06, 10:57am
Hi Jerry,
I am using more or less the same system: I have a phpbb forum with the able2know seo mod from Craven de Kere (http://www.able2know.com/forums/about15132.html). My current phpbb forum is very well indexed in Google; about 37.000 pages. I would like to create a 301 redirect for all those indexed pages, so that visitors for:
www.mydomain.nl/viewtopic.php?t=1234 (http://www.mydomain.nl/viewtopic.php?t=1234)
and
www.mydomain.nl/about1234.html (http://www.mydomain.nl/about1234.html)
are redirected to
www.mydomain.nl/showthread.php?t=5678 (http://www.mydomain.nl/showthread.php?t=5678)
What would be the best way for me to adapt your 404.php script to accept also the /about1234.html urls that are indexed in Google?
Hi Jerry,
I just migrated my forum from phpbb to vbulletin yesterday (impex worked perfectly!) and now I am trying to setup the 301 redirect as I mentioned in my previous post.
I am having some trouble getting this to work however. I downloaded the latest impex (and 404.php along with it) and modified it with the code you gave me for redirecting my aboutxxxx.html files to the correct vbulletin thread. I created a .htaccess file as you specified in the readme and I also have the logging running (added the table to database). When I 'turn on' the script, I am just redirected to the standard404 I entered in the top part of 404.php. Do you have any idea what I am missing?
I guess you'll need more info from me, but instead of me posting the whole script it is probably wiser if you let me know what info you need from me.
Thanks for any help you can give me.
Daniel
dvermeul
Mon 11th Sep '06, 8:40am
Jerry,
I figured it out for the about12345.html links. So, the redirect is working for those links.
However, for the "traditional" phpbb links (e.g. /viewforum.php?f=12 or /viewtopic.php?t=123) the redirect is not working. I tracked it down to $sql statement:
$sql = "SELECT forumid FROM {$tableprefix}forum WHERE importforumid = " . substr($_SERVER['REQUEST_URI'], 2, abs(strpos($_SERVER['REQUEST_URI'], '&',2)-2));
More specifically the substr statement which is supposed to get the importforumid:
substr($_SERVER['REQUEST_URI'], 2, abs(strpos($_SERVER['REQUEST_URI'], '&',2)-2))
This returns "ie" when $_SERVER['REQUEST_URI'] is /viewforum.php?f=19. And well, I don't think there is an importforumid entry for "ie" in the forum table... ;)
So something is going wrong here. Probably for the thread and post parts too. I have some time now, so I'll try to figure it out. I'll keep you posted!
dvermeul
Mon 11th Sep '06, 3:24pm
Ok Jerry, thanks for the tip. I will take a look at it...
In the mean time though, it looks like the current version of 404.php is broken for phpBB users...:(
Jerry
Mon 11th Sep '06, 3:38pm
Ok Jerry, thanks for the tip. I will take a look at it...
In the mean time though, it looks like the current version of 404.php is broken for phpBB users...:(
I wouldn't expect any of the redirects to with the fullname HTML file option in phpBB.
Unless you have :
profile{$old_ext_type}?mode=viewprofile&u=
dvermeul
Mon 11th Sep '06, 3:55pm
I wouldn't expect any of the redirects to with the fullname HTML file option in phpBB.
Unless you have :
profile{$old_ext_type}?mode=viewprofile&u=
Sorry Jerry, I am not sure what you mean...:confused:
From what I gather from the current 404.php (as included in impex 1.66), an out-of-box phpBB installation with links in the SERPS of Google, won't redirect because the substr statement is broken. I think this is probably the same problem sdotson is having.
Just to be clear: I am talking about links like these:
http://www.domain.com/forum/viewforum.php?f=12 (http://www.domain.com/forum/viewforum.php?f=1)
or
http://www.domain.com/forum/viewtopic.php?t=20
In my testing the substr statement delivers 'ie' (as in viewtopic.php) instead of the importtopicid '20' (as in viewtopic.php?t=20)
I hope all this makes some sense to you...
Thanks,
Daniel
Jerry
Mon 11th Sep '06, 4:28pm
Ah ok, the diffrence between the REDIRECT_QUERY_STRING and REQUEST_URI.
In the if statments the REQUEST_URI is used, and REDIRECT_QUERY_STRING used to be used for the rest, the preg_match and the substr etc.
If you change the REQUEST_URI for REDIRECT_QUERY_STRING only inside the if, it should be fine, i.e. :
.......
// It's a thread link
if (strpos($_SERVER['REQUEST_URI'], "/{$old_folder}/{$old_thread_script}") === 0)
{
$action = 'thread';
if( preg_match("/&/", $_SERVER['REDIRECT_QUERY_STRING']) )
{
$sql = "SELECT threadid FROM {$tableprefix}thread WHERE importthreadid = " . substr(substr($_SERVER['REDIRECT_QUERY_STRING'], 2), 0, strpos(substr($_SERVER['REDIRECT_QUERY_STRING'], 2), '&'));
}
else
{
$sql = "SELECT threadid FROM {$tableprefix}thread WHERE importthreadid = " . substr($_SERVER['REDIRECT_QUERY_STRING'], 2);
}
}
.......
dvermeul
Mon 11th Sep '06, 4:49pm
:eek: Jerry, you are a genius!
Now it works like a charm. Just curious... could you explain the difference between REDIRECT_QUERY_STRING and REQUEST_URI? Is there a tradeoff for using one or the other?
Thanks again,
Daniel
Jerry
Mon 11th Sep '06, 4:54pm
REDIRECT_QUERY_STRING I *believe* is the string passed from a redirect and REQUEST_URI is the whole URI from the original request, hence why the substr() was off as the http:// wouldn't of been passed.
Though don't quote me on that, I'm looking into it to get a better understanding to update the script, it seems to be apache dependant, hence why I'm moving to the prag_match(0 technique used for the IPB2 redirects in the script.
So all working and good now ? :)
Using the MySQL table as well to see all the redirects and logging ?
dvermeul
Mon 11th Sep '06, 5:11pm
All is working fine now, thanks to your help! I am updating the rest of the script as we speak...
I am using the logging and will take a closer look as soon as I finish with the script...
So do I understand it correctly that using REDIRECT_QUERY_STRING and REQUEST_URI is dependent on the installation of apache? That would make sense as I am now adapting your 404.php to get it to work for my situation... Wouldn't that be something to include in the readme then, so other users don't run into the same problem?
dvermeul
Mon 11th Sep '06, 6:20pm
Hey Jerry,
I just checked out the logging and noticed that I had to add a few more entries to the 404.php script. Most of them I was able to add very easily, but I am having trouble with one. It turns out the SEO script I used for phpbb has another variant of /aboutxxxx.html up its sleave:
http://www.mydomain.com/about12345-10.html
is a rewrite of
http://www.mydomain.com/viewtopic.php?t=12345&start=10
Could you help me out with a regular expression that redirects from:
http://www.mydomain.com/about12345-10.html
to
http://www.mydomain.com/showthread.php?t=12345
?? I guess I need to strip the -10 part, but my regex knowledge isn't up to par I am afraid. :rolleyes:
As you requested in a previous post, I would like to send you "my" version of 404.php so you can use it to incorporate it in a future version of 404.php. How can I send it to you in the most efficient way?
Thanks,
Daniel
Jerry
Mon 11th Sep '06, 6:53pm
preg_match('#viewtopic.php\?t=([0-9]+)&start=([0-9]+)#is', $_SERVER['REQUEST_URI'], $matches);
threadid = $matches[1]
page = $matches[2]
dvermeul
Mon 11th Sep '06, 7:16pm
Hi Jerry,
I think you misunderstood me. I need a regex for /about12345-10.html... So I am thinking something along the lines of:
preg_match('#(.*)about(.*)-[0-9]+.html#Uis', $_SERVER['REQUEST_URI'], $matches)
But this is probably all wrong...:rolleyes:
Jerry
Mon 11th Sep '06, 7:20pm
preg_match('#about([0-9]+)-([0-9]+).html#is', $moo, $matches);
Sorry, I'll go get some coffee and wake up now before I read posts ......
([0-9+) will ensure you get just numbers (.*) grabs everything, though you were close :)
i.e. :
<?php
$moo = 'http://www.mydomain.com/about12345-10.html';
preg_match('#about([0-9]+)-([0-9]+).html#is', $moo, $matches);
echo "<pre>";
print_r($matches);
echo "</pre>";
?>
dvermeul
Mon 11th Sep '06, 7:41pm
Thanks Jer, that did the trick! Still want a copy of "my" version of 404.php?
Jerry
Mon 11th Sep '06, 7:43pm
Should be good thanks, I've taken the info from here for notes on how to make it more generic.
Powered by vBulletin™ Version 4.0.0 Beta 4 Copyright © 2009 vBulletin Solutions, Inc. All rights