Page 1 of 1
Urgent help needed: Made a failure with renaming titles!
Posted: Thu Sep 07, 2006 12:32 pm
by foobar
Hello folks,
made a big mistake. I renamed my titles the articles. The problem is, is activated smart urls. Some of those urls are indexed in Google.
If Google-Bot visits my site, he will also have the old links in his index. So he will kick them because of double contentent.
The problem depends on the IDs, no matter what is after that IDs the correct article is choosen. So Google have two diffrent links with the same content.
Please help me to fix that. The solution is.
1. take ID and title from url
2. ID and title given by url are the same? Fine->nothing to do
3. If not take the new title build an url and move with header location 302 to that page.
Where must I input that? I can code PHP. So you don´t need to give me the source code. I just wanna know where to put that thing and what is to consider.
If I had time, I could do that by myself. The problem is that Google visits my page every day. So I´am in a big hurry.
Please help me!
Posted: Thu Sep 07, 2006 12:44 pm
by foobar
Correction:
It displays the index. This is bad too.
Edit:
Only if .html at the end is not given.
Re: Urgent help needed: Made a failure with renaming titles!
Posted: Thu Sep 07, 2006 1:24 pm
by garvinhicking
Hi!
You can simply enter your serendipity configuration and there remove the %id% frmo the permalink path to your articles. Then only the true article titles will be used for permalink pattern recognition.
The reason is that if %id% is present, serendipity doesn't bother what else is in the title of the URL, as you already noted. Usually this is good, because of you rename an article, the old URL would no longer be found without the %ID%!
If you want to get your hands into code, check the include/functions_permalink.inc.php file with its functions. If you know PHP, you should get quite familar, the functions are documented what they do.
There you would be able to insert your 302 header relocation. Of course you could also create a plugin that listens on frontend_configure event, then make your permalink matching and if it is disjunct you can 302 redirect to the proper page. Thinking about this, this would be the much wiser thing to do instead of patching code.
You can have a look at the "serendipity_event_custom_permalinks" plugin, which already does something similar.
Best regards,
Garvin
Posted: Thu Sep 07, 2006 1:36 pm
by foobar
Hello Garv
this is my quick patch for serendipity redirect problem:
Not perfect because I have not found the constant for the url:
Code: Select all
/* BEGIN 301 HACK
* Place after in index.php after $title = serendipity_db_query(SELECT title FROM...
*/
$foo = substr($serendipity['uriArguments'][1], strpos($serendipity['uriArguments'][1], '-') + 1, strlen($serendipity['uriArguments'][1]));
if($title[0] != $foo) {
$fooURL = 'http://www.entwickler-blog.de/'.$serendipity['uriArguments'][0].'/'.$id.'-'.$title[0].'.html';
header('HTTP/1.1 301 Moved Permanently');
header('Location: '.$fooURL);
}
/* END 301 HACK */
What do you think?
Posted: Thu Sep 07, 2006 2:01 pm
by foobar
Where is the function to convert the database title to url title?
That thing that replaces " " with "-"?
Edit:
Functions name is: serendipity_makeFilename
Posted: Thu Sep 07, 2006 2:27 pm
by i.speiser
@foobar: I case you have problems with google indexing your page properly (be it because of urls changing or other reasons) you may consider to use the Google Sitemap plugin.
In case there is a serious error in the google index relating your site, you may also apply for deleting it from the index. The procedure is described here:
http://www.google.com/support/webmaster ... topic=8459
Regards
Iris
Posted: Thu Sep 07, 2006 2:31 pm
by foobar
But you where kicked from the index for approximately 6 months if you delete your site from the index.
And with sitemap, you cannot fix that problem correctly, because of the links from other sites, pointing to your page.
Posted: Thu Sep 07, 2006 3:02 pm
by foobar
I think I did it:
Code: Select all
/* BEGIN 301 HACK
* Place after in index.php after $title = serendipity_db_query(SELECT title FROM...
*/
$fooURLTitle = str_replace('.html', '', basename($_SERVER['REQUEST_URI']));
$fooURLTitle = substr($fooURLTitle, strpos($fooURLTitle, '-') + 1, strlen($fooURLTitle));
$fooTitle = serendipity_makeFilename($title[0]);
if($fooTitle != $fooURLTitle) {
if($fooTitle == 'unknown') {
$httpStatus = 'HTTP/1.1 404 Not Found';
$fooURL = 'http://www.entwickler-blog.de';
} else {
$httpStatus = 'HTTP/1.1 301 Moved Permanently';
$fooURL = 'http://www.entwickler-blog.de/'.$serendipity['uriArguments'][0].'/'.$id.'-'.$fooTitle.'.html';
}
header($httpStatus);
header('Location: '.$fooURL);
}
/* END 301 HACK */
Posted: Thu Sep 07, 2006 3:05 pm
by garvinhicking
Hi!
You don't need the hack, you could build your own plugin with it. Have a look at the plugin I mentioned, then you don't need all that URL obfuscating code you posted.
(but your solution should work, I agree to that. But having it as a plugin will make it easier for you to upgrade s9y at a later point)
Regards,
Garvin
Posted: Thu Sep 07, 2006 3:14 pm
by foobar
Sure you right Garvin,
but think, I needed that solution very very quick. Implementing the hack was not really easy in that short time, because I know nothing about the code structure of Serendipity.
If I would trying to create a plugin, I don´t know how long it would take.
So its hack. And I´am fine. If you would help me a little bit out. I would create a plugin for Serendipity, so that all the ppl could easily use it.
What do you make of it, Garvin?
Posted: Thu Sep 07, 2006 3:33 pm
by garvinhicking
Hi!
I understand the urgency.

Now that you have the hack working you might want to take a deep breath and if you have time again look into our cool plugin API?
Best regards,
Garvin
Posted: Thu Sep 07, 2006 3:50 pm
by foobar
Time is the problem, Garvin. I am very busy atm, so playing around is not possible. Okay, you have a technical doc, but if you have a simple "hello world" plugin anywhere I will try to implement it.
Posted: Thu Sep 07, 2006 8:30 pm
by judebert
Here's a simple plugin, modified from
an earlier thread:
Code: Select all
<?php # $Id: serendipity_event_helloworld.php 880 2006-01-27 14:40:21Z garvinhicking $
class serendipity_event_helloworld extends serendipity_event
{
var $title = PLUGIN_EVENT_HELLOWORLD_NAME;
function introspect(&$propbag)
{
global $serendipity;
$propbag->add('name', 'Hello World');
$propbag->add('description', '');
$propbag->add('stackable', false);
$propbag->add('author', 'Garvin Hicking, really');
$propbag->add('version', '1.0');
$propbag->add('requirements', array(
'serendipity' => '0.8',
'smarty' => '2.6.7',
'php' => '4.1.0'
));
//$propbag->add('groups', array('BACKEND_TEMPLATES'));
$propbag->add('event_hooks', array('frontend_display' => true));
}
function generate_content(&$title) {
$title = $this->title;
}
function event_hook($event, &$bag, &$eventData) {
global $serendipity;
$hooks = &$bag->get('event_hooks');
if (isset($hooks[$event])) {
switch($event) {
case 'frontend_display':
echo "<H3>Hello, World!</H3>\n";
return true;
break;
default:
return false;
}
} else {
return false;
}
}
}
/* vim: set sts=4 ts=4 expandtab : */
For more information on what can be done and what hooks are required, we highly recommend checking out other plugins. Searching this forum for event_hook can find many impromptu plugins Garvin has developed for others.