User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Existing Scripts section within the Web Development category of DaniWeb, a massive community of 330,294 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,933 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Existing Scripts advertiser:
Views: 40576 | Replies: 131
Reply
Join Date: Feb 2002
Location: Lawn Guylen, NY
Posts: 10,788
Reputation: cscgal is just really nice cscgal is just really nice cscgal is just really nice cscgal is just really nice cscgal is just really nice 
Rep Power: 32
Solved Threads: 106
Admin
Staff Writer
cscgal's Avatar
cscgal cscgal is online now Online
The Queen of DaniWeb

The quick 'n' dirty ultra simple vBulletin SEO hack

  #1  
Nov 10th, 2005
This is a very quick 'n' simple vBulletin SEO hack. It's easy to apply and it's the one I have been using here on DaniWeb for the past couple of months. I was going to wait until we went vB 3.5 to release it but I might as well do so now ... Disclaimer: This is for vBulletin 3.0.x. It should not be too complicated to port to 3.5 with their hooks system, but I have no experience with 3.5 and therefore don't want to say one way or another. If you use this hack, please link to DaniWeb in your footer. This is a free hack, and it can make or break the traffic to your site. I don't know of any other freely available hacks like this one. Please help us out in exchange for releasing this!

STEP 1: Create an .htaccess file in your forum directory and put the following into it:
  1. Options +FollowSymLinks
  2. RewriteEngine on
  3. RewriteRule ^getdaily.html$ search.php?do=getdaily [L]
  4. RewriteRule ^getdaily([0-9]+).html$ search.php?do=getdaily&f=$1 [L]
  5. RewriteRule ^unanswered.html$ search.php?do=process&replyless=1&replylimit=0&dontcache=1 [L]
  6. RewriteRule ^unanswered([0-9]+).html$ search.php?do=process&replyless=1&replylimit=0&dontcache=1&forumchoice=$1&childforums=1 [L]
  7. RewriteRule ^forum([0-9]+).html$ forumdisplay.php?f=$1 [L]
  8. RewriteRule ^forum([0-9]+)-([0-9]+)-([a-z]+)-(.*)-([0-9]+)-(.*).html$ forumdisplay.php?f=$1&page=$2&sort=$3&order=$4&pp=$5&daysprune=$6 [L]
  9. RewriteRule ^forum([0-9]+)-(.*)-([a-z]+)-([a-z]+).html$ forumdisplay.php?f=$1&daysprune=$2&order=$3&sort=$4 [L]
  10. RewriteRule ^announcement([0-9]+).html$ announcement.php?f=$1 [L]
  11. RewriteRule ^announcement([0-9]+)-([0-9]+).html$ announcement.php?f=$1&announcementid=$2 [L]
  12. RewriteRule ^thread([0-9]+).html$ showthread.php?t=$1 [L]
  13. RewriteRule ^thread([0-9]+)-([0-9]+).html$ showthread.php?t=$1&page=$2 [L]
  14. RewriteRule ^getnew.html$ search.php?do=getnew [L]
  15. RewriteRule ^getnew([0-9]+).html$ search.php?do=getnew&f=$1 [L]
  16. RewriteRule ^printthread([0-9]+).html$ printthread.php?t=$1 [L]
  17. RewriteRule ^sendthread([0-9]+).html$ sendmessage.php?do=sendtofriend&t=$1 [L]
  18. RewriteRule ^referthread([0-9]+)-([0-9]+).html$ showthread.php?t=$1&referrerid=$2 [L]
  19. RewriteRule ^lastpostinthread([0-9]+).html$ showthread.php?goto=lastpost&t=$1 [L]
  20. RewriteRule ^newpostinthread([0-9]+).html$ showthread.php?goto=newpost&t=$1 [L]
  21. RewriteRule ^nextnewesttothread([0-9]+).html$ showthread.php?t=$1&goto=nextnewest [L]
  22. RewriteRule ^nextoldesttothread([0-9]+).html$ showthread.php?t=$1&goto=nextoldest [L]
  23. RewriteRule ^post([0-9]+).html$ showthread.php?p=$1 [L]
  24. RewriteRule ^post([0-9]+)-([0-9]+).html$ showpost.php?p=$1&postcount=$2 [L]
  25. RewriteRule ^post([0-9]+)-([0-9]+)-([0-9]+).html$ showthread.php?p=$1&page=$2&pp=$3 [L]
  26. RewriteRule ^thread([0-9]+)-([a-z]+).html$ showthread.php?mode=$2&t=$1 [L]
  27. RewriteRule ^post([0-9]+)-([a-z]+).html$ showthread.php?p=$1&mode=$2 [L]

STEP 2:

In the includes/functions.php file, below
  1. function print_output($vartext, $sendheader = 1)
  2. {
  3. global $pagestarttime, $query_count, $querytime, $DB_site, $bbuserinfo;
  4. global $vbphrase, $vboptions, $stylevar, $_REQUEST;

in 3.0.7 (in another version of 3.0.x, just put the code below the global declarations in the print_output function) add:

  1. // do Dani's SEO optimization
  2. global $session;
  3.  
  4. $search_array = array(
  5. '#<a ([^>]*)href' . preg_quote("=\"forumdisplay.php?$session[sessionurl]f=") . '([0-9]+)' . preg_quote("&amp;page=") . '([0-9]+)' . preg_quote("&amp;sort=") . '([a-z]*)' . preg_quote("&amp;order="). '([a-z]*)' . preg_quote("&amp;pp=") . '([0-9]*)' . preg_quote("&amp;daysprune="). '([^"]*)"#',
  6. '#<a ([^>]*)href' . preg_quote("=\"forumdisplay.php?$session[sessionurl]f=") . '([0-9]+)' . preg_quote("&amp;daysprune=") . '([^"]*)' . preg_quote("&amp;order=") . '([a-z]*)' . preg_quote("&amp;sort=") . '([a-z]*)' . preg_quote("&amp;pp=") . '([0-9]*)' . preg_quote("&amp;page=") . '([0-9]+)"#',
  7. '#<a ([^>]*)href' . preg_quote("=\"forumdisplay.php?$session[sessionurl]f=") . '([0-9]+)' . preg_quote("&amp;daysprune=") . '([^"^&]*)' . preg_quote("&amp;order=") . '([a-z]*)' . preg_quote("&amp;sort=") . '([a-z]*)"#',
  8. '#<a ([^>]*)href' . preg_quote("=\"forumdisplay.php?$session[sessionurl]f=") . '([0-9]+)' . preg_quote("&amp;daysprune="). '([^"^&]*)"#',
  9. '#<a ([^>]*)href' . preg_quote("=\"forumdisplay.php?$session[sessionurl]f=") . '([0-9]+)' . preg_quote("&amp;page=") . '([0-9]+)"#',
  10. '#<a ([^>]*)href' . preg_quote("=\"forumdisplay.php?$session[sessionurl]f=") . '([0-9]+)"#',
  11. '#<a ([^>]*)href' . preg_quote("=\"showthread.php?$session[sessionurl]t=") . '([0-9]+)' . preg_quote("&amp;page=") . '([0-9]*)' . preg_quote("&amp;pp=") . '([0-9]+)"#',
  12. '#<a ([^>]*)href' . preg_quote("=\"showthread.php?$session[sessionurl]t=") . '([0-9]+)' . preg_quote("&amp;page=") . '([0-9]+)"#',
  13. '#<a ([^>]*)href' . preg_quote("=\"showthread.php?$session[sessionurl]t=") . '([0-9]+)"#',
  14. '#<a ([^>]*)href' . preg_quote("=\"showthread.php?$session[sessionurl]goto=lastpost&amp;t=") . '([0-9]+)"#',
  15. '#<a ([^>]*)href' . preg_quote("=\"showthread.php?$session[sessionurl]goto=newpost&amp;t=") . '([0-9]+)"#',
  16. '#<a ([^>]*)href' . preg_quote("=\"printthread.php?$session[sessionurl]t=") . '([0-9]+)"#',
  17. '#<a ([^>]*)href' . preg_quote("=\"sendmessage.php?$session[sessionurl]do=sendtofriend&amp;t=") . '([0-9]+)"#',
  18. '#<a ([^>]*)href' . preg_quote("=\"showthread.php?$session[sessionurl]t=") . '([0-9]+)' . preg_quote("&amp;goto=next"). '([a-z]+)"#',
  19. '#<a ([^>]*)href' . preg_quote("=\"showthread.php?$session[sessionurl]p=") . '([0-9]+)"#',
  20. '#<a ([^>]*)href' . preg_quote("=\"showthread.php?$session[sessionurl]p=") . '([0-9]+)' . preg_quote("&amp;page=") . '([0-9]+)' . preg_quote("&amp;pp=") . '([0-9]+)"#',
  21. '#<a ([^>]*)href' . preg_quote("=\"showpost.php?$session[sessionurl]p=") . '([0-9]+)' . preg_quote("&amp;postcount=") . '([0-9]+)"#',
  22. '#<a ([^>]*)href' . preg_quote("=\"showthread.php?$session[sessionurl]mode=") . '([a-z]+)' . preg_quote("&amp;t=") . '([0-9]+)"#',
  23. '#<a ([^>]*)href' . preg_quote("=\"showthread.php?$session[sessionurl]p=") . '([0-9]+)' . preg_quote("&amp;mode=") . '([a-z]+)\##',
  24.  
  25. '#<a ([^>]*)href' . preg_quote("=\"announcement.php?$session[sessionurl]f=") . '([0-9]+)' . preg_quote("&amp;announcementid=") . '([0-9]+)"#',
  26. '#<a ([^>]*)href' . preg_quote("=\"announcement.php?$session[sessionurl]f=") . '([0-9]+)"#',
  27.  
  28. // sanitizing
  29. '#<a ([^>]*)href\=\"([^"]*)&amp;page=([^"]*).html"#',
  30. '#<a ([^>]*)href\=\"([^"]*)&amp;highlight=([^"]*).html"#',
  31.  
  32. // other
  33. '#<a ([^>]*)href' . preg_quote("=\"search.php?$session[sessionurl]do=getdaily&amp;f=") . '([0-9]*)"#',
  34. '#<a ([^>]*)href' . preg_quote("=\"search.php?$session[sessionurl]do=getdaily") . '"#',
  35. '#<a ([^>]*)href' . preg_quote("=\"search.php?$session[sessionurl]do=process&amp;replyless=1&amp;replylimit=0&amp;dontcache=1&amp;forumchoice=&amp;childforums=1") . '"#',
  36. '#<a ([^>]*)href' . preg_quote("=\"search.php?$session[sessionurl]do=process&amp;replyless=1&amp;replylimit=0&amp;dontcache=1&amp;forumchoice=") . '([0-9]+)' . preg_quote("&amp;childforums=1") . '"#'
  37.  
  38. );
  39. $replace_array = array(
  40. '<a \1href="forum\2-\3-\4-\5-\6-\7.html"',
  41. '<a \1href="forum\2-\7-\5-\4-\6-\3.html"',
  42. '<a \1href="forum\2-\3-\4-\5.html"',
  43. '<a \1href="forum\2-\3.html"',
  44. '<a \1href="forum\2-\3.html"',
  45. '<a \1href="forum\2.html"',
  46. '<a \1href="thread\2-\3.html"',
  47. '<a \1href="thread\2-\3.html"',
  48. '<a \1href="thread\2.html"',
  49. '<a \1href="lastpostinthread\2.html"',
  50. '<a \1href="newpostinthread\2.html"',
  51. '<a \1href="printthread\2.html"',
  52. '<a \1href="sendthread\2.html"',
  53. '<a \1href="next\3tothread\2.html"',
  54. '<a \1href="post\2.html"',
  55. '<a \1href="post\2-\3-\4.html"',
  56. '<a \1href="post\2-\3.html"',
  57. '<a \1href="thread\3-\2.html"',
  58. '<a \1href="post\2-\3.html#',
  59.  
  60. '<a \1href="announcement\2-\3.html"',
  61. '<a \1href="announcement\2.html"',
  62.  
  63. // sanitizing
  64. '<a \1href="\2-\3.html"',
  65. '<a \1href="\2-\3.html"',
  66.  
  67. // other
  68. '<a \1href="getdaily\2.html"',
  69. '<a \1href="getdaily.html"',
  70. '<a \1href="unanswered.html"',
  71. '<a \1href="unanswered\2.html"'
  72.  
  73. );
  74. $vartext = preg_replace($search_array, $replace_array, $vartext);
Please do not duplicate all or part of this code elsewhere. Thanks should go out to Xenon for suggesting to me that I can rewrite URLs from within this function. Thanks!! ... And, please, give credit where credit is due - if you use this hack, please link back.
Last edited by cscgal : Mar 21st, 2007 at 2:36 am. Reason: Updated to use new code tags
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2005
Posts: 1
Reputation: Club2share.com is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Club2share.com Club2share.com is offline Offline
Newbie Poster

Re: The quick 'n' dirty ultra simple vBulletin SEO hack

  #2  
Nov 12th, 2005
Verynice Hack and is there any chanse we can get this work like the VBSeo from vbseo.com ?
Reply With Quote  
Join Date: Feb 2002
Location: Lawn Guylen, NY
Posts: 10,788
Reputation: cscgal is just really nice cscgal is just really nice cscgal is just really nice cscgal is just really nice cscgal is just really nice 
Rep Power: 32
Solved Threads: 106
Admin
Staff Writer
cscgal's Avatar
cscgal cscgal is online now Online
The Queen of DaniWeb

Re: The quick 'n' dirty ultra simple vBulletin SEO hack

  #3  
Nov 13th, 2005
Update:

I just took a look at vB 3.5. Based on what I can see - and this still goes untested - add the .htaccess file as mentioned above. Then, throw all the PHP code into the global_complete hook. The only difference to make is the last line should read:

  1. $output = preg_replace($search_array, $replace_array, $output);

We're doing a find/replace on the parsed $output instead of the raw $vartext because, quite simply, a hook doesn't exist earlier in the function. So hopefully it will work.


If for whatever reason that above hook doesn't work, the fail-safe way that will 100% work in vB 3.5 is to add the exact code as in the original tutorial below:
  1. function print_output($vartext, $sendheader = true)
  2. {
  3. global $pagestarttime, $querytime, $vbulletin;
  4. global $vbphrase, $stylevar;
Last edited by cscgal : Jun 14th, 2007 at 12:00 am.
Reply With Quote  
Join Date: Feb 2002
Location: Lawn Guylen, NY
Posts: 10,788
Reputation: cscgal is just really nice cscgal is just really nice cscgal is just really nice cscgal is just really nice cscgal is just really nice 
Rep Power: 32
Solved Threads: 106
Admin
Staff Writer
cscgal's Avatar
cscgal cscgal is online now Online
The Queen of DaniWeb

Re: The quick 'n' dirty ultra simple vBulletin SEO hack

  #4  
Nov 13th, 2005
Originally Posted by Club2share.com
Verynice Hack and is there any chanse we can get this work like the VBSeo from vbseo.com ?

Using directories can be accomplished by simply replacing the .html postfix areas of the code with the / prefix as necessary.

I haven't investigated the code close enough to know whether this function has access to the $thread['title'] variable ... I assume that it does, and if so, you can simply use it in the PHP code, but it remains untested.
Reply With Quote  
Join Date: Dec 2004
Posts: 34
Reputation: Kwak is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
Kwak Kwak is offline Offline
Light Poster

Help Re: The quick 'n' dirty ultra simple vBulletin SEO hack

  #5  
Nov 14th, 2005
Hello cscgal,

I've applied the hack to a new style and followed step by step (3 steps was easy ).
I found a bug though.
The multi-page links return a 404 error.

The multi-page link show up as
http://www.daniweb.com/techtalkforums/-1-20.html

rather than

http://www.daniweb.com/techtalkforum...ad34695-1.html
Reply With Quote  
Join Date: Feb 2002
Location: Lawn Guylen, NY
Posts: 10,788
Reputation: cscgal is just really nice cscgal is just really nice cscgal is just really nice cscgal is just really nice cscgal is just really nice 
Rep Power: 32
Solved Threads: 106
Admin
Staff Writer
cscgal's Avatar
cscgal cscgal is online now Online
The Queen of DaniWeb

Re: The quick 'n' dirty ultra simple vBulletin SEO hack

  #6  
Nov 14th, 2005
This hack has been tested to have no problems on both a vB 3.0.7 installation as well as a vB 3.5 installation - both by editing the functions.php file as mentioned above. It has not yet been tested using the 3.5 hooks method.

Which version are you working with?
Reply With Quote  
Join Date: Dec 2004
Posts: 34
Reputation: Kwak is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
Kwak Kwak is offline Offline
Light Poster

Re: The quick 'n' dirty ultra simple vBulletin SEO hack

  #7  
Nov 14th, 2005
Originally Posted by cscgal
This hack has been tested to have no problems on both a vB 3.0.7 installation as well as a vB 3.5 installation - both by editing the functions.php file as mentioned above. It has not yet been tested using the 3.5 hooks method.

Which version are you working with?
It is for version 3.0.3.
I may have edited a few templates from the previous mod_rewrite hack so I'll get on this later this week and see where the problem lies. Thanks.
Reply With Quote  
Join Date: Feb 2002
Location: Lawn Guylen, NY
Posts: 10,788
Reputation: cscgal is just really nice cscgal is just really nice cscgal is just really nice cscgal is just really nice cscgal is just really nice 
Rep Power: 32
Solved Threads: 106
Admin
Staff Writer
cscgal's Avatar
cscgal cscgal is online now Online
The Queen of DaniWeb

Re: The quick 'n' dirty ultra simple vBulletin SEO hack

  #8  
Nov 14th, 2005
Yes, that seems like it's almost definitely the problem.
Reply With Quote  
Join Date: Dec 2004
Posts: 34
Reputation: Kwak is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
Kwak Kwak is offline Offline
Light Poster

Re: The quick 'n' dirty ultra simple vBulletin SEO hack

  #9  
Nov 16th, 2005
I've reverted the templates and files to the default stage. And whala~ everything is good to go.


Except two things:

1) New post links in the forumhome goes to the .php page rather than .html.
e.g. http://www.daniweb.com/techtalkforum...hread2379.html link takes you to http://www.daniweb.com/techtalkforum...4318#post14318


2) In the online.php? page, if the visitor (a google bot) is looking at a specific posts in a thread, e.g. http://www.daniweb.com/techtalkforum...08#postid=8308
it shows up as a .php? rather than a .html

but all other threads show up properly as .html. So only when a member or a visitor is at a specific post, the link in the online.php? page shows up in such a way.
Reply With Quote  
Join Date: Feb 2002
Location: Lawn Guylen, NY
Posts: 10,788
Reputation: cscgal is just really nice cscgal is just really nice cscgal is just really nice cscgal is just really nice cscgal is just really nice 
Rep Power: 32
Solved Threads: 106
Admin
Staff Writer
cscgal's Avatar
cscgal cscgal is online now Online
The Queen of DaniWeb

Re: The quick 'n' dirty ultra simple vBulletin SEO hack

  #10  
Nov 17th, 2005
My hack only alters URLs in templates, not URLs that were generated in the php files themselves. If you want to fix problem #1 you illustrated, you would have to start editing PHP files. It's a trade off whether you want to be 100% SEO'ed or whether you want the hack to be self-contained. For me, I don't care about it redirecting to the non-SEO'd version as long as the spiders get a taste of newpostinthread.html and lastpostinthread.html

To answer your second question, I didn't bother SEO'ing this because spiders never see the online.php page, it should be set to members-only access.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb Marketplace (Sponsored Links)
Thread Tools Display Modes

Similar Threads
Other Threads in the Existing Scripts Forum

All times are GMT -4. The time now is 6:40 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC