Go Back   vb.org Archive > vBulletin Modifications > vBulletin 4.x Modifications > vBulletin 4.x Add-ons
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
Custom SEO urls (mod_rewrite only) Details »»
Custom SEO urls (mod_rewrite only)
Version: 4.0-0.1 a4, by Carnage Carnage is offline
Developer Last Online: Sep 2014 Show Printable Version Email this Page

Category: Miscellaneous Hacks - Version: 4.0.0 Rating:
Released: 12-28-2009 Last Update: 01-18-2010 Installs: 43
Template Edits
Re-useable Code Code Changes Additional Files Is in Beta Stage  
No support by the author.

What does this do?
This mod allows you to define the beginning part of all the friendly urls. Eventually, more of the url may be customizable but this should be enough to provide a nice structure to your site anyway. I have now released this as more of a mod to make it easier for the less technical admins.

What use is this to me?
I can see a couple of major uses here.
1. If you want to translate the friendly urls into your local language (so instead of having http://example.com/threads/123-Test-Thread/ you have http://example.com/[translation]/123-Test-thread)
2. You want a bit more structure to your links eg forum/threads, forum/posts, blogs/entries etc
3. You just don't like the defaults you've been stuck with and want to change to t,p,f,b and e

Installation
1. First step here, is to ensure that the default mod rewrite urls work for you. Upload the default .htaccess file from the do_not_upload folder to your forums and switch on mod rewrite friendly urls in the server settings and optimisations area of your control panel.
2.Browse around your forums and check that all the links still work. (If they don't you need to work with vb support and your host to get them working)
3. Upload the contents of the upload folder in the zip.
4. Import the product.
5. There is now a new option group in your admin cp; friendly url settings. Change these to your liking.
5a. There is also a link to the rewrite rule generator from the settings page; once you've got the settings to your liking, visit the link to generate a .htaccess file. Alternativly follow the instructions below to make your own.
6. Once you've made these changes, you need to edit your .htaccess file rewrite rules to reflect the changes you made. You need to replicate the change to this file that you've made to the options. you will see a set of:
Code:
RewriteRule ^threads/([0-9]+)(?:/?$|(?:-[^/]+))(?:/?$|(?:/page([0-9]+)?)) showthread.php?t=$1&page=$2&%{QUERY_STRING}
RewriteRule ^members/([0-9]+) member.php?u=$1&%{QUERY_STRING}
RewriteRule ^forums/([0-9]+)(?:/?$|(?:-[^/]+))(?:/?$|(?:/page([0-9]+)?)) forumdisplay.php?f=$1&page=$2&%{QUERY_STRING}
RewriteRule ^blogs/([0-9]+)(?:/?$|(?:-[^/]+))(?:/?$|(?:/page([0-9]+)?)) blog.php?u=$1&page=$2&%{QUERY_STRING}
RewriteRule ^entries/([0-9]+)(?:/?$|(?:-[^/]+))(?:/?$|(?:/page([0-9]+)?)) entry.php?b=$1&page=$2&%{QUERY_STRING}
You need to change the red bits to match your settings.

7. (Optional) Extra credit. Some people want the /forums/ to point to the forumindex page and /blogs/ to point to blog.php the following rewrite rules will take care of this. These should be added to the .htaccess file (don't overwrite any existing rules, these are new ones)

Code:
RewriteRule ^forums/(index.php)?$ forum.php?%{QUERY_STRING}
RewriteRule ^blogs/(index.php)?$ blog.php?%{QUERY_STRING}
Finally do a search of your templates + phrases for occurrences of forum.php and blog.php and change them to forums/index.php and blogs/index.php (or forums/ and blogs/) respectively.

forums.domain.com and blogs.domain.com support
This is not quite as easy as the above and requires a file edit to achieve.
If you are using 4.0.1; you can skip the file edit part as it appears to work without.
1. Make a backup copy of includes/class_friendly_url.php
2. Around line 604 find:
PHP Code:
        // REQUEST_URI is dependable for apache
        
if (isset($_SERVER['REQUEST_URI']))
        {
            
// return the raw url
            
$url $_SERVER['REQUEST_URI'];
            
$url $this->registry->input->strip_sessionhash($url);

            return 
$url;
        } 
Replace

PHP Code:
$url $_SERVER['REQUEST_URI']; 
with
PHP Code:
$url 'http://' $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; 
3. In your apache config or appropriate server config file, set a serveralias for the subdomains you want to use (eg forums.domain.com) You may need to contact your host for help with this step.
4. In the vbulletin control panel set the cookie domain to be .yourdomain.com
I dont know if this will have any knock on effects elsewhere, but it seems to be working for me on my dev board.
5. You can now set a value for forums to be http://forums.domain.com and blogs to be http://blogs.domain.com or similar based upon your requirement.
6. Rewrite rules are a bit more complex for this setup; this is a good resource for getting the server side stuff setup: http://www.reconn.us/content/view/46/67/

example rewrite rules:

Code:
RewriteCond %{HTTP_HOST} ^(www.)?forums.domain.com$ [NC]
RewriteRule ^threads/([0-9]+)(?:/?$|(?:-[^/]+))(?:/?$|(?:/page([0-9]+)?)) showthread.php?t=$1&page=$2&%{QUERY_STRING}
RewriteRule ^members/([0-9]+) member.php?u=$1&%{QUERY_STRING}
RewriteRule ^/([0-9]+)(?:/?$|(?:-[^/]+))(?:/?$|(?:/page([0-9]+)?)) forumdisplay.php?f=$1&page=$2&%{QUERY_STRING}
RewriteRule ^/(index.php)?$ forum.php?%{QUERY_STRING}

RewriteCond %{HTTP_HOST} ^(www.)?blogs.domain.com$ [NC]
RewriteRule ^entries/([0-9]+)(?:/?$|(?:-[^/]+))(?:/?$|(?:/page([0-9]+)?)) entry.php?b=$1&page=$2&%{QUERY_STRING}
RewriteRule ^/(index.php)?$ blog.php?%{QUERY_STRING}
RewriteRule ^/([0-9]+)(?:/?$|(?:-[^/]+))(?:/?$|(?:/page([0-9]+)?)) blog.php?u=$1&page=$2&%{QUERY_STRING}
Changelog
  • 4.0-0.1 a4
    • Added file to generate rewrite rules
    • Removed old instructions from this post to prevent confusion.
  • 4.0-0.1 a3
    • Fixed missing settings in product file.
  • 4.0-0.1 a2
    • Released as product
  • 4.0-0.1 a1
    • Initial release

Notes
  • forums.domain.com and blogs.domain.com is possible, but requires a file edit; Instructions above)
  • adding extra information to urls is /not/ currently possible (eg tags, forum name to threads etc)
  • if you want a custom url format, post what you would like and if its possible, I can give you more pointers on how to implement it.
  • if you change your url format, you may want to leave the old rewrite rules in making a copy of them instead of editing them.
  • if you want the old instructions, for manual file edits (advanced users only) pm me.
  • There is some experimental code now attached, this provides an example of how to create custom uri formats (includes forum name in thread urls) but is no where near finished and is for advanced users (read coders) only. This functionality will be built into the product once its been tested and is more stable.

Download Now

File Type: zip Custom Friendly URL's v4.0-0.1 alpha 4.zip (17.5 KB, 426 views)
File Type: zip experimental.zip (9.3 KB, 222 views)

Screenshots

File Type: jpg customurls.jpg (89.7 KB, 0 views)

Show Your Support

  • This modification may not be copied, reproduced or published elsewhere without author's permission.
Благодарность от:
Naijasite

Comments
  #42  
Old 01-19-2010, 12:29 PM
Skyrider Skyrider is offline
 
Join Date: Feb 2006
Location: Netherlands
Posts: 1,392
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

This is a really nice plugin, that's for sure.. But I have a small issue. As soon as I alter the links, the previous SEO URL will give a 404 / dead link. Anyway possible that the old SEO (For example, the RewriteRule ^forums/ can be "forward" to the new url without touching the whole link? So the whole link from:

www.xxx.com/forums/34-test to www.xxx.com/sections/34-test will merely forward forums to sections without touching the whole link together.

Second, is it also possible to get rid of the whole "forums"? so instead of:

www.xxx.com/forums/34-test

It will show:

www.xxx.com/34-test
Reply With Quote
  #43  
Old 01-19-2010, 01:34 PM
Carnage Carnage is offline
 
Join Date: Jan 2005
Location: uk
Posts: 760
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
if you change your url format, you may want to leave the old rewrite rules in making a copy of them instead of editing them.
From the notes, i mentioned this. Essentially if you do that (and your old rules are compatible with the new ones) vb will redirect to the correct url.

For your second question; i've not tried every possible combination of rewrites; but that one should work.
Reply With Quote
  #44  
Old 01-19-2010, 02:22 PM
BBF BBF is offline
 
Join Date: Dec 2006
Location: Israel, Netanya.
Posts: 97
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Carnage- View Post
That one isn't easilly possible, the id needs to be avaliable somewhere for vb to use to query the db with.
so just leave the id and add the name
domain.com/forums/10-off-topic

or something like this.
Reply With Quote
  #45  
Old 01-19-2010, 03:05 PM
Brandon Sheley's Avatar
Brandon Sheley Brandon Sheley is offline
 
Join Date: Mar 2005
Location: Google Kansas
Posts: 4,678
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

will this work with a sitemap?
if not, than I don't find it useful ?
Reply With Quote
  #46  
Old 01-19-2010, 04:51 PM
Carnage Carnage is offline
 
Join Date: Jan 2005
Location: uk
Posts: 760
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
so just leave the id and add the name
domain.com/forums/10-off-topic
Thats the default setting without installing this mod. If you have your forums installed in forums however, setting the forums prefix to be blank will probably do this. (If you get a // in the url set it to http://www.domain.com/forums instead)

Quote:
will this work with a sitemap?
if not, than I don't find it useful ?
Ive not tested it with the site map; I assume that the sitemap uses the get_friendly_url() function thou, provided it does, then this will work with the sitemap.
Reply With Quote
  #47  
Old 01-23-2010, 05:14 PM
WxP's Avatar
WxP WxP is offline
 
Join Date: Dec 2005
Location: Albania
Posts: 104
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

i get this error:

No thread specified. If you followed a valid link, please notify the administrator

but link is in this mode:
/showthread.php?Prshndetje-dhe-Urime/KiSs-8111
Reply With Quote
  #48  
Old 01-23-2010, 06:09 PM
Carnage Carnage is offline
 
Join Date: Jan 2005
Location: uk
Posts: 760
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

@WxP

1. It seems you are using the experimental code to create links. You need to create your own rewrite rules for this to work. It's also experimental if you can't get it working on your own, you will have to wait untill I've got the code more stable and included it in the main product.

2. You don't have the friendly urls set to mod_rewrite. This mod only works if you use that setting.

3. I'm guessing here but if you put the id right at the front of the url (eg before even the forum) it /might/ work as you've got it setup. eg:
/showthread.php?8111-Prshndetje-dhe-Urime/KiSs
Reply With Quote
  #49  
Old 01-26-2010, 10:25 AM
Carnage Carnage is offline
 
Join Date: Jan 2005
Location: uk
Posts: 760
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Added a screenshot of the options provided by this mod.
Reply With Quote
  #50  
Old 01-26-2010, 10:54 PM
WxP's Avatar
WxP WxP is offline
 
Join Date: Dec 2005
Location: Albania
Posts: 104
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

i do all this you can check!

i put this code in .htaccess

Code:
#Credits: Christopher Riley, Vbulletin, http://www.vbulletin.com/forum/showthread.php?325798 
#File was made with the best bits from all the above.

#turn on and setup rewrite engine
RewriteEngine On
Options +FollowSymLinks

### THIS IS A LITTLE EXTRA SECURITY AND CAN BE REMOVED
#Has to be at the top else it wouldn't get past the accident prevention rules

RewriteRule ^includes/(.*) index.php
RewriteRule ^vb/(.*) index.php
RewriteRule ^packages/(.*) index.php

#Prevent rewriting files; this will/should stop accidentilly hiding images/js etc from the browser
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]

#these rules can't be edited by my mod, so leave them as are.
RewriteRule ^content/(.*) content.php?r=$1&%{QUERY_STRING}
RewriteRule ^widget/config/([0-9]+) widget.php?r=config/$1&%{QUERY_STRING} 
RewriteRule ^list/([^/]*/)([0-9]+) list.php?r=$1$2&%{QUERY_STRING}
RewriteRule ^/threads/([0-9]+)(?:/?$|(?:-[^/]+))(?:/?$|(?:/page([0-9]+)?)) showthread.php?t=$1&page=$2&%{QUERY_STRING}
RewriteRule ^members/([0-9]+) member.php?t=$1&%{QUERY_STRING}
RewriteRule ^blogs/([0-9]+)(?:/?$|(?:-[^/]+))(?:/?$|(?:/page([0-9]+)?)) blog.php?u=$1&page=$2&%{QUERY_STRING}
RewriteRule ^forums/([0-9]+)(?:/?$|(?:-[^/]+))(?:/?$|(?:/page([0-9]+)?)) forumdisplay.php?f=$1&page=$2&%{QUERY_STRING}
RewriteRule ^entries/([0-9]+)(?:/?$|(?:-[^/]+))(?:/?$|(?:/page([0-9]+)?)) entry.php?b=$1&page=$2&%{QUERY_STRING}
#You can remove the # in front of one of these rules to rewrite blogs/ or blogs/index.php to blogs.php 
#(sorry i've no way to automatically detect If you are likely to need this or not)
#RewriteRule ^blogs/(index.php)$ forum.php?%{QUERY_STRING} 
#RewriteRule ^blogs/index.php$ forum.php?%{QUERY_STRING}
Reply With Quote
  #51  
Old 01-27-2010, 09:32 AM
Carnage Carnage is offline
 
Join Date: Jan 2005
Location: uk
Posts: 760
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

RewriteRule ^/threads/([0-9]+)(?:/?$|(?:-[^/]+))(?:/?$|(?:/page([0-9]+)?)) showthread.php?t=$1&page=$2&%{QUERY_STRING}

should be

RewriteRule ^threads/([0-9]+)(?:/?$|(?:-[^/]+))(?:/?$|(?:/page([0-9]+)?)) showthread.php?t=$1&page=$2&%{QUERY_STRING}

Thats either a bug in my script, or you put a / at the beggining of your threads setting
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 05:28 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.08262 seconds
  • Memory Usage 2,369KB
  • Queries Executed 26 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (4)bbcode_code
  • (3)bbcode_php
  • (4)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_post
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (4)pagenav_pagelink
  • (11)post_thanks_box
  • (1)post_thanks_box_bit
  • (11)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (11)post_thanks_postbit_info
  • (10)postbit
  • (3)postbit_attachment
  • (11)postbit_onlinestatus
  • (11)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_attachment
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete