MyBB Community Forums

Full Version: MyBB SEO- Public BETA Testing Ground
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5 6 7 8 9 10
$seo_forumname = str_replace('+', '_', urlencode($forum['name']));

Urlencode replaces a space with +, and encodes other characters, to a form that will pass W3 validation.
( like & to $amp; )
Detruire Wrote:( like & to & )
You're thinking of htmlspecialchars(), not urlencode().

MyBB already runs htmlspecialchars() on the forum and thread names, so that shouldn't be a concern.

As for other characters that shouldn't be in a URL, they should also just be replaced with underscores, or even removed, since the goal is to make the URLs look as nice as possible. Smile
Never used it..

Quote:As for other characters that shouldn't be in a URL, they should also just be replaced with underscores, or even removed, since the goal is to make the URLs look as nice as possible.

Too true. If you want pretty you should stick with either _ or - not swap and change after the id.

It is easy enough with mod_rewrite. Smile

edit:
Why not do something like what Devshed has done, which is slightly better looking then how this way will end up.
use underscore!
Detruire Wrote:Why not do something like what Devshed has done, which is slightly better looking then how this way will end up.
You mean like this? (forum name, forum ID, thread name, thread ID)

/php-development-5/form-validation-is-this-needed-323647.html
/php-development-5/cookie-phpsessid-is-set-but-i-can-t-find-the-323403.html

That looks pretty good... they strip down the URLs pretty aggressively... removing all capitalization and non-alphanumeric characters...
WDZ Wrote:
Detruire Wrote:Why not do something like what Devshed has done, which is slightly better looking then how this way will end up.
You mean like this? (forum name, forum ID, thread name, thread ID)

/php-development-5/form-validation-is-this-needed-323647.html
/php-development-5/cookie-phpsessid-is-set-but-i-can-t-find-the-323403.html

That looks pretty good... they strip down the URLs pretty aggressively... removing all capitalization and non-alphanumeric characters...
That could be a possibiliy, but for the first release I will keep it the way it is with capitals.
I personally think dashes should be used as seperators with underscores separating spaces and dashes in the forum/topic title. Makes it more human readable imho.
And just to point out, rawurlencode and urlencode produce different results. If you didn't know one or the other existed, might be interesting to look into both.
WDZ Wrote:Well, for example, this is a snippet of the HTML of your index page...

<a href="forum-5-Testing Forum.html">Testing Forum</a>

Which you want to have an underscore in it like so...

<a href="forum-5-Testing_Forum.html">Testing Forum</a>

And I assume your template currently looks like this...

<a href="forum-$forum[fid]-$forum[name].html">$forum[name]</a>

What you need is a new variable containing the forum name with all spaces replaced with underscores. You would need to add a line of PHP code like this to index.php (for this example) to create that variable...

$seo_forumname = str_replace(" ", "_", $forum['name']);
Then use the new $seo_forumname variable in your <a href="..."> code.

Of course, this modification may have to be done in many places... wherever you use a forum name in one of your SEO URLs. Oh, and the thread names too. It might be possible to use the plugins system to some extent to help ease the task of making all those modifications, but I'm not sure...
Hi,
Okay, I added the code you provided to my index.php file:
$seo_forumname = str_replace(" ", "_", $forum['name']);

I changed the url in my template to:
Quote:forum-$forum[fid]-$seo_forumname.html

Now, if you mouseover the link, all that shows up is:
Quote:http://www.mydevote.com/forum/forum-5-.html

Is there something I did wrong? Thanks!
It took me ages to figure out something like this last night.

If you are using a plugin function in the hook 'index_forum' and try to make a variable global using 'global' it DOES NOT WORK.

To really make it global (even in the function that cycles the forums) you need to make it global in the start of THAT function.

so, even to use the $forum variable, you need to change
global $fcache, $moderatorcache, $forumpermissions, $theme, $mybb, $mybbforumread, $settings, $mybbuser, $excols, $fcollapse, $templates, $bgcolor, $collapsed, $lang, $showdepth, $forumpass, $plugins;
to
global $fcache, $moderatorcache, $forumpermissions, $theme, $mybb, $mybbforumread, $settings, $mybbuser, $excols, $fcollapse, $templates, $bgcolor, $collapsed, $lang, $showdepth, $forumpass, $plugins, $forum;

If that is not your problem, where did you put the line?
kodaks Wrote:Is there something I did wrong? Thanks!
Well, how good is your PHP knowledge? I'm assuming you know where to place the new code, but just in case you don't, I'd suggest placing it right after this code in index.php, around line 236...
$plugins->run_hooks("index_forum");
If it works there, then you'll know it will work if you decide to make it a plugin in the future. Smile
Pages: 1 2 3 4 5 6 7 8 9 10