News:

Wondering if this will always be free?  See why free is better.

Main Menu

Search Engine Friendly URLs

Started by CA3LE, January 20, 2005, 04:04:42 AM

Previous topic - Next topic

CA3LE

First of all SMF is the shiz!  Converting from phpBB has shown me all the stuff I was missing... I will never look back!

NOW, on to the issue

Am I missing something here?  I have read many posts about this but am still scratching my head.

All I want is for the URL's to look like

THIS
http://testmy.net/forum/index.php/topic,1628.html
(better yet http://testmy.net/topic,1628.html)

NOT THIS
http://testmy.net/forum/index.php?topic=1628.0


Linux server with Apache 1.3.33
PHP 4.3.10
Show URLs without ?'s is checked

I have even at one point commented out and added to /$SMFROOT$/Sources/QueryString.php

//   elseif (!empty($modSettings['queryless_urls']) && !$context['server']['is_cgi'] && $context['server']['is_apache'])
      elseif (!empty($modSettings['queryless_urls']))

(sadly did nothing for me)


phpinfo()  if you need it  -------  just ask what portion you want

Can you see why this is not working with my server, does it need to be in SAPI mode... from what I have read it does, can someone help me to understand how I can get PHP in sapi mode.   Or whatever I need to do.  I run a dedicated server so it's not a matter of "calling my host" ... anything that needs to be done I can take care of, I just need a nudge in the right direction.

(oh yea.. real quick, whoever helps me... spell check does not work either... maybe related? -- lemme know what I need installed for this, I read a while back but have forgotten.)

Can someone please help  ;)

- Thanks in advance!

Oldiesmann

I don't know enough about PHP to tell you how to get it in SAPI mode, but [Unknown] can probably tell you that. As far as spell check - you need to have ASpell installed and then re-compile PHP with "-- with-pspell" in the configure command... ASpell can be downloaded at http://aspell.sf.net

Alexandre P.

For the Search Engine Friendly URLs, in you Admin Center > Edit features and options > Basic Forum Features > Search engine friendly URLs, there should be a button.  A popup will open and tells you if this function will work on your forum.
Aucun support par M.P., courriel ou messagerie instantanée / No support by P.M., email or I.M.

CA3LE

clicked it .. and it says...

This changes the format of URLs a little so search engines will like them better. They will look like index.php/action_profile/u_1.

This feature will work on your server.

Close window

CA3LE

By the way... as for the spell checking I did compile and install aspell... but I forgot to re-build apache... DUR, now it works great.

[Unknown]

Could you give the actual link to your forum?

-[Unknown]

CA3LE


[Unknown]

Well, it does, at least, look like they should work on your server.

http://testmy.net/forum/index.php/board,5.0

Try this for the last function in QueryString.php:

// Rewrite URLs to include the session ID.
function ob_sessrewrite($buffer)
{
global $scripturl, $modSettings, $user_info, $context;

// If $scripturl is set to nothing, or the SID is not defined (SSI?) just quit.
if ($scripturl == '' || !defined('SID'))
return $buffer;

// Do nothing if the session is cookied, or they are a crawler - guests are caught by redirectexit().  This doesn't work below PHP 4.3.0, because it makes the output buffer bigger.
if (empty($_COOKIE) && SID != '' && (!$user_info['is_guest'] || (strpos($_SERVER['HTTP_USER_AGENT'], 'Mozilla') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'Opera') !== false)))
$buffer = preg_replace('/"' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')(\?)?/', '"' . $scripturl . '?' . SID . '&', $buffer);
// You can't do both, because session_start() won't catch the session if you do.  But this should work even in 4.2.x, just not CGI.
else
$buffer = preg_replace('/"' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+)(#[^"]*)?"/e', "'\"' . \$scripturl . '/' . strtr('\$1', '&;=', '//,') . '.html\$2\"'", $buffer);

// Return the changed buffer.
return $buffer;
}


-[Unknown]

CA3LE

Quote from: [Unknown] on January 22, 2005, 08:55:25 AM
Well, it does, at least, look like they should work on your server.

http://testmy.net/forum/index.php/board,5.0

Try this for the last function in QueryString.php:

// Rewrite URLs to include the session ID.
function ob_sessrewrite($buffer)
{
global $scripturl, $modSettings, $user_info, $context;

// If $scripturl is set to nothing, or the SID is not defined (SSI?) just quit.
if ($scripturl == '' || !defined('SID'))
return $buffer;

// Do nothing if the session is cookied, or they are a crawler - guests are caught by redirectexit().  This doesn't work below PHP 4.3.0, because it makes the output buffer bigger.
if (empty($_COOKIE) && SID != '' && (!$user_info['is_guest'] || (strpos($_SERVER['HTTP_USER_AGENT'], 'Mozilla') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'Opera') !== false)))
$buffer = preg_replace('/"' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')(\?)?/', '"' . $scripturl . '?' . SID . '&', $buffer);
// You can't do both, because session_start() won't catch the session if you do.  But this should work even in 4.2.x, just not CGI.
else
$buffer = preg_replace('/"' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+)(#[^"]*)?"/e', "'\"' . \$scripturl . '/' . strtr('\$1', '&;=', '//,') . '.html\$2\"'", $buffer);

// Return the changed buffer.
return $buffer;
}


-[Unknown]

Changed it.. still no luck .... ????

[Unknown]

Very strange.  It's working for a few of the URLs but not all of them.  I'm not sure why that would happen, as they look the same to me.

-[Unknown]

CA3LE

#10
Just a follow up, I got this fixed.

For anyone who needs to know in the future... here was the fix for my specific application

I edited

Sources/BoardIndex.php
Sources/Display.php
Sources/MessageIndex.php

to reflect the new URLs for instance



'<a href="' . $scripturl . '?topic=' .


becomes


'<a href="' . $scripturl2 . '/topic-' .


and do the same format for topics if you'd like... don't bother changing throughout the entire forum, that isn't the point to this, message indexes and board indexes are all you need to change, what I have edited is actually more than I needed to do I think... but hey, it works great so I'm not going to get too picky.

and I of course defined


$scripturl2 = '/';


I don't remember where I added that... but it should be able to be added to index.php if your lazy.  The only reason I defined that instead of just leaving it $scripturl is because I wanted it escaped from the forum directory.


and added the following in .htaccess

RewriteEngine On
RewriteRule ^topic-([^/]+)[/]?$ /forum/index.php?topic=$1
RewriteRule ^board-([^/]+)[/]?$ /forum/index.php?board=$1

End result was the board URLs look like  >> http://testmy.net/board-5 and topics for instance look like http://testmy.net/topic-2160 -

By the way, I have noticed that this will still work with SMF even if you don't check "Show URLs without ?'s" in the options -- but don't fool yourself into thinking all is good... session errors occur if this isn't checked.

a few days ago Inktomi Slurp had over 300 bots in my forum spidering the crap out of it... then the other day I saw MSNBot, EchO!,  Walhello appie, WISENutbot, LinkWalker and Netcraft going deeper than I have ever logged.  Googlebot should be in there in a few days.. that one will be interesting.  Google has a cache of about 7200 pages of my site and I have about 21,000 posts total in the forum... I should be able to tell success when Google gets their hands on my site again and I re-query.  I will try and remember to post here with my findings ;-)

Thank you for your help... I guess I was just misunderstanding the use of that option.  I thought it would change all the links...

and [unknown] - from what I have read in this forum... you are a stand up kinda guy, congratulations.. and VERY nice scripting indeed.

CA3LE

in 8 days google has added over 2500 more of my pages .. I will keep updating... this is only the start because google and other engines have been in my forums very heavy the past week.

Daevien

Don't forget to add $scripturl2 to the global vars section as well at the top of the files :)

CA3LE

Quote from: Jaeren on February 12, 2005, 01:35:04 AM
Don't forget to add $scripturl2 to the global vars section as well at the top of the files :)

Yea I did explain that wrong a bit... you actually can do it about 3 different ways, one including removing $scripturl2 completely... but you know what I meant  ;-)

Anyway, I checked Google again and a query for site:testmy.net is now showing 18,000+ entries ~ much better than the previous 7200 (or whatever it was) ~ this number is still on the upswing and Googles bots (along with all the other guys) are in my forum all the time now keeping stuff up-to-date ~~~ this change really boosted my visibility ;)

flyingmembers

I see Ca3le came up with one solution, but having followed his posts I came up with a few problems...can anyone help me and go through this post again...I'm sure It'll benefit others.

Also you might want to check out:
http://www.submitexpress.com/analyzer/

Then enter your forum url and check how many pages are spidered, then start the changes below and then try it again...

If anyone can help me on this, that'll be great!

Quote from: CA3LE on February 02, 2005, 06:13:01 AM
Just a follow up, I got this fixed.

For anyone who needs to know in the future... here was the fix for my specific application

I edited

Sources/BoardIndex.php
Sources/Display.php
Sources/MessageIndex.php

to reflect the new URLs for instance



'<a href="' . $scripturl . '?topic=' .


becomes


'<a href="' . $scripturl2 . '/topic-' .


and do the same format for topics if you'd like... don't bother changing throughout the entire forum, that isn't the point to this, message indexes and board indexes are all you need to change, what I have edited is actually more than I needed to do I think... but hey, it works great so I'm not going to get too picky.

and I of course defined


$scripturl2 = '/';


I don't remember where I added that... but it should be able to be added to index.php if your lazy.  The only reason I defined that instead of just leaving it $scripturl is because I wanted it escaped from the forum directory.


and added the following in .htaccess

RewriteEngine On
RewriteRule ^topic-([^/]+)[/]?$ /forum/index.php?topic=$1
RewriteRule ^board-([^/]+)[/]?$ /forum/index.php?board=$1

End result was the board URLs look like  >> http://testmy.net/board-5 and topics for instance look like http://testmy.net/topic-2160 -

By the way, I have noticed that this will still work with SMF even if you don't check "Show URLs without ?'s" in the options -- but don't fool yourself into thinking all is good... session errors occur if this isn't checked.

a few days ago Inktomi Slurp had over 300 bots in my forum spidering the crap out of it... then the other day I saw MSNBot, EchO!,  Walhello appie, WISENutbot, LinkWalker and Netcraft going deeper than I have ever logged.  Googlebot should be in there in a few days.. that one will be interesting.  Google has a cache of about 7200 pages of my site and I have about 21,000 posts total in the forum... I should be able to tell success when Google gets their hands on my site again and I re-query.  I will try and remember to post here with my findings ;-)

Thank you for your help... I guess I was just misunderstanding the use of that option.  I thought it would change all the links...

and [unknown] - from what I have read in this forum... you are a stand up kinda guy, congratulations.. and VERY nice scripting indeed.


[Unknown]

Search engines barely look at meta tags these days...

-[Unknown]

flyingmembers

But if you run most forums through:
http://www.submitexpress.com/analyzer/

You'll see the actual topic posts aren't spidered at all, even if Search Friendly Mod switched on in Apache.

Hope either yourself or Ca3le could help me with the text above as I entered it into my forum and still couldn't get it working...I think I need an "Idiot's Guide" in order to use the above code...

Daevien

#17
Basically, you are opening the Sources/BoardIndex.php, Sources/Display.php & Sources/MessageIndex.php files and changing  the lines that contain stuff like


'<a href="' . $scripturl . '?topic=' .


into stuff like


'<a href="' . $scripturl2 . '/topic-' .


You can also change the ones that are for the board listings as well, just search for ?board= and change them the same way as you changes the ones for the topics.

Also you need to go look at the lines that declare the global variables such as


global $scripturl, $txt, $db_prefix, $modSettings, $context, $settings, $options, $sourcedir;


and add $scripturl2 as in like


global $scripturl, $scripturl2, $txt, $db_prefix, $modSettings, $context, $settings, $options, $sourcedir;


$scripturl2 is set somewhere (i think i used the base index.php file when i did it to one of my sites) to be the base url of your site (http://yoursite.com [nofollow] or http://yoursite.com/forums [nofollow] for example, also just / should work, i think i defined my full url in any case) and then it add the /topic- to the url giving you something like http://yoursite.com/topic-1234 [nofollow] for topic 1234

If you used $scripturl which is always defined by smf for it's own purposes you could end with some funky urls, hence the extra variable

The modifications set what SMF returns for linking to urls in the board index, etc instead of the standard way.

But... That's only half of it. You still need to have your web server to redirect the /topic- urls to the proper locations

For apache servers, you can do it with .htaccess files as long as they are enabled (usually are for commercial hosting companies) and do what was suggest above:


RewriteEngine On
RewriteRule ^topic-([^/]+)[/]?$ /forum/index.php?topic=$1
RewriteRule ^board-([^/]+)[/]?$ /forum/index.php?board=$1


For other servers, I can't tell you right off what you would have to do for the equiv settings, maybe if you aren't running apache, you can tell me what software you do use and i'll see what I can find.

(Note, I hacked up CA3LE's initial posts into a slightly different layout with some different explanations. Hopefully It made ands ense and was all correct but as I just got home from a long shift and it's late at night, I give you no guarantee ;) )

I may look into doing up a quick mod for this, I'll see what time I have over the next few days if it would be something peopel would use.

[Unknown]

Quote from: flyingmembers on February 23, 2005, 08:01:59 PM
But if you run most forums through:
http://www.submitexpress.com/analyzer/

You'll see the actual topic posts aren't spidered at all, even if Search Friendly Mod switched on in Apache.

So, obviously, that tool knows absolutely nothing.

-[Unknown]

flyingmembers

Thanks Jaeren, but I personally still encountered the same problems.  If you check out my site:
http://www.flyingmembers.com/forums/

All the pages have HTML which is great, however individual posts aren't showing the /forums/ url bit, can I break up your post....

"Basically, you are opening the Sources/BoardIndex.php..."

If you search for '<a href="' . $scripturl . '?topic=' . on Sources/BoardIndex.php you won't find any matches.  I found x2 matches on Sources/Display.php and x4 on Sources/MessageIndex.php.

Am I supposed to replace all instances of .?topic= to /topic- ?

"Also you need to go look at the lines that declare the global variables..."

Could you confirm that "scripturl2" needs to be placed on all .template.php files such as:
global $context, $settings, $options, $scripturl, $scripturl2, $txt, $modSettings;

"$scripturl2 is set somewhere..."

The definition of scripturl2 needs to go in forum/index.php near the top at?:
// Get everything started up...
define('SMF', 1);
@set_magic_quotes_runtime(0);
error_reporting(E_ALL);
$scripturl2 = 'http://www.mywebsite/forum/';

"For apache servers, you can do it with .htaccess files..."

Finally, does the .htaccess file go into the Root directory or the actual forum/ directory?

RewriteEngine On
RewriteRule ^topic-([^/]+)[/]?$ /forum/index.php?topic=$1
RewriteRule ^board-([^/]+)[/]?$ /forum/index.php?board=$1

Advertisement: