Der Short URL Mod ist da ja schonmal nicht schlecht, hilft aber den Suchmaschienen an vielen Stellen den Doppelten Content zu entdecken. Die URLs ptopic123.html schadet meiner Meinung nach mehr als sie nutzt. Deshalb hab ich viel Probiert und Lösungen gesucht um die URLs abzuschaffen.
1. Die .htaccess
Code: Alles auswählen
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} /forums.html
RewriteRule (.*) /index.php [L]
RewriteCond %{REQUEST_FILENAME} /viewforum([0-9]*)-([0-9]*)-([0-9]*).html
RewriteRule (.*) /viewforum.php?f=%1&topicdays=%2&start=%3 [L]
RewriteCond %{REQUEST_FILENAME} /forum([0-9]*).html
RewriteRule (.*) /viewforum.php?f=%1 [L]
RewriteCond %{REQUEST_FILENAME} /ftopic([0-9]*)-([0-9]*)-([a-zA-Z]*)-([0-9]*).html
RewriteRule (.*) /viewtopic.php?t=%1&postdays=%2&postorder=%3&start=%4 [L]
RewriteCond %{REQUEST_FILENAME} /ftopic([0-9]*)-([0-9]*).html
RewriteRule (.*) /viewtopic.php?t=%1&start=%2 [L]
RewriteCond %{REQUEST_FILENAME} /ftopic([0-9]*).html
RewriteRule (.*) /viewtopic.php?t=%1 [L]
RewriteCond %{REQUEST_FILENAME} /ftopic([0-9]*).html
RewriteRule (.*) /viewtopic.php?t=%1&start=%2&postdays=%3&postorder=%4&highlight=%5 [L]
RewriteCond %{REQUEST_FILENAME} /user-([0-9]*).html
RewriteRule (.*) /profile.php?mode=viewprofile&u=%1 [L]
öffne die /includes/page_header.php und f�ge vor
Code: Alles auswählen
//
// Generate logged in/logged out status
//
Code: Alles auswählen
//
// Short URL implementation
//
// start buffering
ob_start();
function replace_for_mod_rewrite(&$s) {
// get the correct base_url: protocoll,url,path to make sure to rewrite only internal links
if (empty($HTTP_SERVER_VARS['HTTP_HOST'])) {
$server = getenv('HTTP_HOST');
} else {
$server = $HTTP_SERVER_VARS['HTTP_HOST'];
}
// IIS sets HTTPS=off
if (isset($HTTP_SERVER_VARS['HTTPS']) && $HTTP_SERVER_VARS['HTTPS'] != 'off') {
$proto = 'https://';
} else {
$proto = 'http://';
}
// Get the name of this URI
// Start of with REQUEST_URI
if (isset($HTTP_SERVER_VARS['REQUEST_URI'])) {
$path = $HTTP_SERVER_VARS['REQUEST_URI'];
} else {
$path = getenv('REQUEST_URI');
}
if ((empty($path)) || (substr($path, -1, 1) == '/')) {
// REQUEST_URI was empty or pointed to a path
// Try looking at PATH_INFO
$path = getenv('PATH_INFO');
if (empty($path)) {
// No luck there either
// Try SCRIPT_NAME
if (isset($HTTP_SERVER_VARS['SCRIPT_NAME'])) {
$path = $HTTP_SERVER_VARS['SCRIPT_NAME'];
} else {
$path = getenv('SCRIPT_NAME');
}
}
}
$path = preg_replace('/[#\?].*/', '', $path);
$path = dirname($path);
if (preg_match('!^[/\\\]*$!', $path)) {
$path = '';
}
$base_url = "$proto$server$path/";
$prefix = '|"(?:'.$base_url.')?';
// now that we know about the correct $prefix we can start the rewriting
$urlin =
array(
$prefix . '(?<!/)index.php"|',
$prefix . '(?<!/)viewforum.php\?f=([0-9]*)&(?:amp;)topicdays=0&(?:amp;)start=0"|',
$prefix . '(?<!/)viewforum.php\?f=([0-9]*)&(?:amp;)topicdays=([0-9]*)&(?:amp;)start=([0-9]*)"|',
$prefix . '(?<!/)viewforum.php\?f=([0-9]*)"|',
$prefix . '(?<!/)viewtopic.php\?t=([0-9]*)&(?:amp;)postdays=0&(?:amp;)postorder=asc&(?:amp;)start=0"|',
$prefix . '(?<!/)viewtopic.php\?t=([0-9]*)&(?:amp;)postdays=0&(?:amp;)postorder=asc&(?:amp;)start=([0-9]*)"|',
$prefix . '(?<!/)viewtopic.php\?t=([0-9]*)&(?:amp;)postdays=([0-9]*)&(?:amp;)postorder=([a-zA-Z]*)&(?:amp;)start=([0-9]*)"|',
$prefix . '(?<!/)viewtopic.php\?t=([0-9]*)&(?:amp;)start=([0-9]*)&(?:amp;)postdays=([0-9]*)&(?:amp;)postorder=([a-zA-Z]*)&(?:amp;)highlight=([a-zA-Z0-9]*)"|',
$prefix . '(?<!/)viewtopic.php\?t=([0-9]*)&(?:amp;)start=0"|',
$prefix . '(?<!/)viewtopic.php\?t=([0-9]*)&(?:amp;)start=([0-9]*)"|',
$prefix . '(?<!/)viewtopic.php\?t=([0-9]*)"|',
$prefix . '(?<!/)profile.php\?mode=viewprofile&(?:amp;)u=([0-9]*)"|',
);
$urlout = array(
'"forums.html"',
'"forum\\1.html"',
'"viewforum\\1-\\2-\\3.html"',
'"forum\\1.html"',
'"ftopic\\1.html"',
'"ftopic\\1-\\2.html"',
'"ftopic\\1-\\2-\\3-\\4.html"',
'"ftopic\\1.html"',
'"ftopic\\1.html"',
'"ftopic\\1-\\2.html"',
'"ftopic\\1.html"',
'"user-\\1.html"',
);
$s = preg_replace($urlin, $urlout, $s);
return $s;
}
Code: Alles auswählen
$db->sql_close();
Code: Alles auswählen
//
// ShortURL implementation
//
$contents = ob_get_contents();
ob_end_clean();
echo replace_for_mod_rewrite($contents);
Code: Alles auswählen
$gzip_contents = ob_get_contents();
Code: Alles auswählen
//
// Short URL implementation
//
$gzip_contents = replace_for_mod_rewrite($gzip_contents);
3. Der Link zum letzten Beitrag
Um statt ptopic123.html eine URL im Stil von ftopic123.html#123 zu erhalten und um doppelten Content zu verhindern muss in der /includes/session.php
Code: Alles auswählen
function append_sid($url, $non_html_amp = false)
{
global $SID;
Code: Alles auswählen
function append_sid($url, $non_html_amp = false)
{
global $SID,$HTTP_SERVER_VARS,$db,$board_config;
if( strstr($url,'viewtopic.php') && !strstr($url,'viewtopic.php?replace') )
{
if(ereg("#",$url)) {
$pos=strpos($url, "#");
$url_temp=substr($url,0,$pos);
$zusatz=substr($url,$pos,strlen($url));
$url=$url_temp;
}
else
{
$zusatz="";
}
$found=false;
$found_subject_topic=false;
$found_subject_forum=false;
if( preg_match('#viewtopic.php\?p=#', $url) )
{
$prg=str_replace("viewtopic.php?","",$url);
parse_str($prg, $prg_output);
$sql = "SELECT topic_id
FROM " . POSTS_TABLE . "
WHERE post_id = '".$prg_output['p']."'";
if ($result = $db->sql_query($sql))
{
$row = $db->sql_fetchrow($result);
$prg_output['t'] = $row['topic_id'];
$sql = "SELECT post_id
FROM " . POSTS_TABLE . "
WHERE post_id < '".$prg_output['p']."'
AND topic_id = '".$prg_output['t']."'";
if ($result = $db->sql_query($sql))
{
$c = $db->sql_numrows($result)+1;
if ($board_config['posts_per_page'] < $c)
$prg_output['start'] = floor(($c-1) / $board_config['posts_per_page']) * $board_config['posts_per_page'];
}
if (isset($prg_output['start']))
$url = preg_replace('#viewtopic.php\?p='.$prg_output['p'].'#','ftopic'.$prg_output['t'].'-'.$prg_output['start'].'.html',$url);
else
$url = preg_replace('#viewtopic.php\?p='.$prg_output['p'].'#','/ftopic'.$prg_output['t'].'.html',$url);
unset($prg_output['p']);
}
}
}