News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Change Topic URL To the Subject Of IT

Started by SAFAD, August 01, 2009, 03:57:37 PM

Previous topic - Next topic

SAFAD

Hi
I Know That Is Better To Use Pretty URLS
But Its Not Working With Arabic
So I must Do It Manually
I Must Edit QueryString.php
and add
            $id=<some_thing>;
            $query = db_query("
                SELECT t.ID_TOPIC, t.ID_BOARD, m.subject
                FROM {$db_prefix}topics AS t
                    INNER JOIN {$db_prefix}messages AS m ON (m.ID_MSG = t.ID_FIRST_MSG)
                WHERE t.ID_TOPIC = $id" , __FILE__, __LINE__);
            while ($row = mysql_fetch_assoc($query))
                {
                    $str = $row['subject'];
                }

And
$buffer = preg_replace('/"' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?"/e', "'\"' . \$scripturl . '/' . strtr('\$1', '&;=', '//,') . '.$str.html\$2\"'", $buffer);

Now I Need To Define $ID
I Mean How To Get TopicID & Or BoardID

And Yes There Is Arabic URLS
And It Was Working After I Make Some Changes On GoogleSeo For MyBB
And I Yes It Was Working So Good
And No My Forum Still A Bit NewBie With Google (PR1)
Google Doesn't Like To See A Big Site Has Big Visitors And A Big PR Use This Kind Of URLS
And Best Regards
Best Regards
Sadaoui "SAFAD" Abderrahim - Lead Developer @ Electron Inc.

Arantor

First of all, please repost this without WYSIWYG so we can see the actual code you're looking at and what you're trying to do.
Holder of controversial views, all of which my own.


TheDisturbedOne

I don't think I have ever seen a URL in Arabic...

Arantor

You will see them on Wikipedia, actually. Some browsers choke on it, as do some web servers, where they're not designed to cope with UTF-8 input. Strictly speaking this is what the url-encode system is about, sanitising it to make it 7-bit safe.

Also reports suggest that making the URL non-dynamic and putting the name in doesn't actually help search engine ranking and - recently according to Google - may hurt it.
Holder of controversial views, all of which my own.


TheDisturbedOne

Really? I never heard that.  It seems to have actually helped mine.

SAFAD

Hi
I Opened The Source Of SMFSEO <= oldest mod i saw!!!

and extracted this from it

$boardcount = preg_match_all('/"' . preg_quote($scripturl, '/') . '\?board=([^#";.]+).*?"/e', $bufferold, $testboards, PREG_PATTERN_ORDER);

$topiccount = preg_match_all('/"' . preg_quote($scripturl, '/') . '\?topic=([^#";.]+).*?"/e', $bufferold, $testtopics, PREG_PATTERN_ORDER);

if(isset($testboards)) { $testboards = array_unique($testboards[1]); }
if(isset($testtopics)) { $testtopics = array_unique($testtopics[1]); }

// Ooops. We need to get rid of any non-numbers here.
   foreach ($testtopics as $index => $value) {
       if (!is_numeric($value)) unset($testtopics[$index]);
   }
   foreach ($testboards as $index => $value) {
       if (!is_numeric($value)) unset($testboards[$index]);
   }

if (count($testtopics) > 0) {

$temptopics = implode(",", $testtopics);

// Find the topic text for the temptopics.
$cnsql="SELECT t.ID_TOPIC as ID_TOPIC, t.ID_BOARD as ID_BOARD, t.topic_text as topic_text, b.board_text as board_text
FROM ".$db_prefix."topic_lookup AS t, ".$db_prefix."boards AS b
WHERE t.ID_BOARD = b.ID_BOARD
AND t.ID_TOPIC IN (".$temptopics.")";
$request = db_query($cnsql, __FILE__, __LINE__);

if (mysql_num_rows($request) == 0) { return; }

while ($row = mysql_fetch_assoc($request))
{
$topic_id_array[] = $row['ID_TOPIC'];
$topic_text_array[] = $row['topic_text'];
$board_text_array[] = $row['board_text'];
}
mysql_free_result($request);

iwill try it and report back
Best Regards
Sadaoui "SAFAD" Abderrahim - Lead Developer @ Electron Inc.

SAFAD

That Code Didn't Work After *Upgrade*
White Page
Need Help Guys
Best Regards
Sadaoui "SAFAD" Abderrahim - Lead Developer @ Electron Inc.

Arantor

And is there an error in the webserver log, if so what is it? Likely the code is missing a { or two.
Holder of controversial views, all of which my own.


SAFAD

Nothing There
And Am Pretty Sure That Evry Thing Is Fine


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

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



// SMFSEO - Let's get some URL's to rewrite!
$boardcount = preg_match_all('/"' . preg_quote($scripturl, '/') . '\?board=([^#";.]+).*?"/e', $bufferold, $testboards, PREG_PATTERN_ORDER);

$topiccount = preg_match_all('/"' . preg_quote($scripturl, '/') . '\?topic=([^#";.]+).*?"/e', $bufferold, $testtopics, PREG_PATTERN_ORDER);

if(isset($testboards)) { $testboards = array_unique($testboards[1]); }
if(isset($testtopics)) { $testtopics = array_unique($testtopics[1]); }

// Ooops. We need to get rid of any non-numbers here.
   foreach ($testtopics as $index => $bufferue) {
       if (!is_numeric($bufferue)) unset($testtopics[$index]);
   }
   foreach ($testboards as $index => $bufferue) {
       if (!is_numeric($bufferue)) unset($testboards[$index]);
   }

if (count($testtopics) > 0) {

$temptopics = implode(",", $testtopics);

// Find the topic text for the temptopics.
$cnsql="SELECT t.ID_TOPIC as ID_TOPIC, t.ID_BOARD as ID_BOARD, t.topic_text as topic_text, b.board_text as board_text
FROM ".$db_prefix."topic_lookup AS t, ".$db_prefix."boards AS b
WHERE t.ID_BOARD = b.ID_BOARD
AND t.ID_TOPIC IN (".$temptopics.")";
$request = db_query($cnsql, __FILE__, __LINE__);

if (mysql_num_rows($request) == 0) { return; }

while ($row = mysql_fetch_assoc($request))
{
$topic_id_array[] = $row['ID_TOPIC'];
$topic_text_array[] = $row['topic_text'];
$board_text_array[] = $row['board_text'];
}
mysql_free_result($request);

for ($i = 0, $n = count($topic_id_array); $i < $n; $i++)
{
// the topic urls
$topicfromcache[] = '"' . preg_quote($scripturl, '/') . '\?topic=(' . preg_quote($topic_id_array[$i], '/') . ')\.((?:from|msg|new|)[0-9]*).*?"';


$topictocache[] = $boardurl.'/'.$board_text_array[$i].'/'.$topic_text_array[$i].'.$2.html';


}

$buffer = preg_replace($topicfromcache, $topictocache, $buffer);
}

$board_id_array = null;
$board_text_array = null;

if (count($testboards) > 0) {

$tempboards = implode(",", $testboards);

// Find the board text for the tempboards.
$cnsql="SELECT ID_BOARD, board_text
FROM ".$db_prefix."boards
WHERE ID_BOARD IN (".$tempboards.")";
$request = db_query($cnsql, __FILE__, __LINE__);

if (mysql_num_rows($request) == 0) { return; }

while ($row = mysql_fetch_assoc($request))
{
$board_id_array[] = $row['ID_BOARD'];
$board_text_array[] = $row['board_text'];
}
mysql_free_result($request);

for ($i = 0, $n = count($board_id_array); $i < $n; $i++)
{
// the normal board URLs
$boardfromcache[] = '"' . preg_quote($scripturl, '/') . '\?board=(' . preg_quote($board_id_array[$i], '/') . ')\.([0-9]*).*?"';


$boardtocache[] = $boardurl.'/'.$board_text_array[$i].'/index.$2.html';


// those pesky ;sort=([a-zA-Z]+);start=(\d)* type urls
$boardfromcache2[] = '"' . preg_quote($scripturl, '/') . '\?board=(' . preg_quote($board_id_array[$i], '/') . ')(;sort=[a-zA-Z]*);start=([0-9]*).*?"';


$boardtocache2[] = $boardurl.'/'.$board_text_array[$i].'/index.$3.html$2';


}

$buffer = preg_replace($boardfromcache, $boardtocache, $buffer);
$buffer = preg_replace($boardfromcache2, $boardtocache2, $buffer);
}



// Return the changed buffer.
return $buffer;
// Chris Nolan - SMFSEO - End
}

Best Regards
Sadaoui "SAFAD" Abderrahim - Lead Developer @ Electron Inc.

Arantor

Then your server is harshly configured. If you're getting a white page something is clearly and definitely wrong and there should be an entry in the log to confirm what it was.
Holder of controversial views, all of which my own.


SAFAD

LocalHost Can It Be Wrong ?
hmmmmmmm
o i Must Edit Even News.php
So Look What I Did




// Rewrite URLs to include the session ID.
function fix_possible_url($val)
{
global $scripturl, $modSettings, $user_info, $context, $db_prefix, $boardurl;

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



// SMFSEO - Let's get some URL's to rewrite!
$boardcount = preg_match_all('/"' . preg_quote($scripturl, '/') . '\?board=([^#";.]+).*?"/e', $valold, $testboards, PREG_PATTERN_ORDER);

$topiccount = preg_match_all('/"' . preg_quote($scripturl, '/') . '\?topic=([^#";.]+).*?"/e', $valold, $testtopics, PREG_PATTERN_ORDER);

if(isset($testboards)) { $testboards = array_unique($testboards[1]); }
if(isset($testtopics)) { $testtopics = array_unique($testtopics[1]); }

// Ooops. We need to get rid of any non-numbers here.
   foreach ($testtopics as $index => $value) {
       if (!is_numeric($value)) unset($testtopics[$index]);
   }
   foreach ($testboards as $index => $value) {
       if (!is_numeric($value)) unset($testboards[$index]);
   }

if (count($testtopics) > 0) {

$temptopics = implode(",", $testtopics);

// Find the topic text for the temptopics.
$cnsql="SELECT t.ID_TOPIC as ID_TOPIC, t.ID_BOARD as ID_BOARD, t.topic_text as topic_text, b.board_text as board_text
FROM ".$db_prefix."topic_lookup AS t, ".$db_prefix."boards AS b
WHERE t.ID_BOARD = b.ID_BOARD
AND t.ID_TOPIC IN (".$temptopics.")";
$request = db_query($cnsql, __FILE__, __LINE__);

if (mysql_num_rows($request) == 0) { return; }

while ($row = mysql_fetch_assoc($request))
{
$topic_id_array[] = $row['ID_TOPIC'];
$topic_text_array[] = $row['topic_text'];
$board_text_array[] = $row['board_text'];
}
mysql_free_result($request);

for ($i = 0, $n = count($topic_id_array); $i < $n; $i++)
{
// the topic urls
$topicfromcache[] = '"' . preg_quote($scripturl, '/') . '\?topic=(' . preg_quote($topic_id_array[$i], '/') . ')\.((?:from|msg|new|)[0-9]*).*?"';


$topictocache[] = $boardurl.'/'.$board_text_array[$i].'/'.$topic_text_array[$i].'.$2.html';


}

$val = preg_replace($topicfromcache, $topictocache, $val);
}

$board_id_array = null;
$board_text_array = null;

if (count($testboards) > 0) {

$tempboards = implode(",", $testboards);

// Find the board text for the tempboards.
$cnsql="SELECT ID_BOARD, board_text
FROM ".$db_prefix."boards
WHERE ID_BOARD IN (".$tempboards.")";
$request = db_query($cnsql, __FILE__, __LINE__);

if (mysql_num_rows($request) == 0) { return; }

while ($row = mysql_fetch_assoc($request))
{
$board_id_array[] = $row['ID_BOARD'];
$board_text_array[] = $row['board_text'];
}
mysql_free_result($request);

for ($i = 0, $n = count($board_id_array); $i < $n; $i++)
{
// the normal board URLs
$boardfromcache[] = '"' . preg_quote($scripturl, '/') . '\?board=(' . preg_quote($board_id_array[$i], '/') . ')\.([0-9]*).*?"';


$boardtocache[] = $boardurl.'/'.$board_text_array[$i].'/index.$2.html';


// those pesky ;sort=([a-zA-Z]+);start=(\d)* type urls
$boardfromcache2[] = '"' . preg_quote($scripturl, '/') . '\?board=(' . preg_quote($board_id_array[$i], '/') . ')(;sort=[a-zA-Z]*);start=([0-9]*).*?"';


$boardtocache2[] = $boardurl.'/'.$board_text_array[$i].'/index.$3.html$2';


}

$val = preg_replace($boardfromcache, $boardtocache, $val);
$val = preg_replace($boardfromcache2, $boardtocache2, $val);
}



// Return the changed buffer.
return $val;
// Chris Nolan - SMFSEO - End
}




Best Regards
Best Regards
Sadaoui "SAFAD" Abderrahim - Lead Developer @ Electron Inc.

SAFAD

Best Regards
Sadaoui "SAFAD" Abderrahim - Lead Developer @ Electron Inc.

SAFAD

Best Regards
Sadaoui "SAFAD" Abderrahim - Lead Developer @ Electron Inc.

Arantor

So which bit exactly are you still having trouble with?

The thing is, it *really* isn't necessary to make the URL contain the topic title for SEO purposes.
Holder of controversial views, all of which my own.


SAFAD

I Really Need It
When I Use That Code White Page
You Said It Is Host Problem
But Its LocalHost
Best Regards
Sadaoui "SAFAD" Abderrahim - Lead Developer @ Electron Inc.

Arantor

So what's in your localhost error log?
Holder of controversial views, all of which my own.


SAFAD

mmmmmm
searched very around
no errors!!

Quote
[Wed Aug 12 15:41:03 2009] [error] [client ::1] PHP Fatal error:  Call to undefined function db_query() in /opt/lampp/htdocs/smf/Sources/QueryString.php on line 542, referer: http://localhost/smf/install.php?step=5
[Wed Aug 12 15:42:01 2009] [error] [client ::1] PHP Fatal error:  Call to undefined function db_query() in /opt/lampp/htdocs/smf/Sources/QueryString.php on line 542, referer: http://localhost/smf/install.php?step=5

and when i refresh or reenter page
nothing more this is the last thing
i use xampp for linux
and i replaced db_query with mysql_query
and still white and there is nothing in error log
Best Regards
Sadaoui "SAFAD" Abderrahim - Lead Developer @ Electron Inc.

SAFAD

Still the same
is there any configuration that i must do ?
Best Regards
Sadaoui "SAFAD" Abderrahim - Lead Developer @ Electron Inc.

SAFAD

Please I Really Need This Help
And I Leted My Visitors Wait Me Alot Cuz I Am Trying To Train Them To Be 'Seo Pro'
Best Regards
Sadaoui "SAFAD" Abderrahim - Lead Developer @ Electron Inc.

Advertisement: