Als Zwischenstand und auch als 'Request for Comments' hier nun einmal das aktuell im nuForum im Einsatz befindliche Rewriting - quasi als Release Candidate und nicht zum Einsatz in Produktivumgebungen - das gilt insbesondere wenn man sich mit dem Thema nicht auskennt.
Einige grundsätzliche Dinge bitte ich zu beachten
- Die Grundlagen zum Rewriting sind im o.a. Topic ausführlich beschrieben, hier geht es um Optimierungen die noch nicht wirklich ausgetestet sind
- Das Rewriting via preg_replace kostet Performance, je umfangreicher umso mehr (das nuForum läuft auf einem eigenen Server)
- Eventuelle Fragen zum Einsatz der .htaccess am Besten an den Provider richten, es gibt teilweise auch unterschiedliche Syntaxmöglichkeiten
- Die folgenden Snippets sind aktuell erst einmal für Testumgebungen gedacht - und sollten nur von Leuten ausprobiert werden, die sich mit dem Thema Rewriting bereits auseinandergesetzt haben.
- Die u.a. Snippets beziehen sich teilweise auch auf im nuForum integrierte Mods/Hacks
Bislang bekannte Probleme
- Die Suche nach allen Beiträgen von Benutzern mit bestimmten Sonderzeichen ('+') funktioniert (noch) nicht - wer eine regexp für im phpBB2 erlaubte Benutzer greifbar hat bitte melden

Weiterführende Informationen rund um das Thema Suchmaschinen-Optimierung und auch eine für die Short URLs angepasste Google Sitemap finden sich übrigens auch in meinem SEO-Blog.
Short URLs für phpBB2 (reloaded / RFC)
Anpassungen gegenüber dem Original-Topic
als neue .htaccess (Pfadangaben ggfs. anpassen!) [1]
Code: Alles auswählen
RewriteEngine On
# prevent access from santy webworm a-e
RewriteCond %{QUERY_STRING} ^(.*)highlight=\%2527 [OR]
RewriteCond %{QUERY_STRING} ^(.*)rush=\%65\%63\%68 [OR]
RewriteCond %{QUERY_STRING} ^(.*)rush=echo [OR]
RewriteCond %{QUERY_STRING} ^(.*)wget\%20 [OR]
RewriteCond %{QUERY_STRING} ^(.*)cmd=
RewriteRule ^.*$ http://127.0.0.1/ [R,L]
# prevent pre php 4.3.10 bug
RewriteCond %{HTTP_COOKIE}% s:(.*):\%22test1\%22\%3b
RewriteRule ^.*$ http://127.0.0.1/ [R,L]
# prevent perl user agent (most often used by santy)
RewriteCond %{HTTP_USER_AGENT} ^lwp.* [NC]
RewriteRule ^.*$ http://127.0.0.1/ [R,L]
# extended rewriting only for .html [thx to Caterham]
RewriteRule !\.html$ - [L]
# Short URL implementation [larsneo]
RewriteCond %{REQUEST_URI} ^/nuforum/forums\.html
RewriteRule (.*) /nuforum/index.php [R=301,L]
RewriteCond %{REQUEST_URI} ^/nuforum/index-mark\.html
RewriteRule (.*) /nuforum/index.php?mark=forums [L]
RewriteCond %{REQUEST_URI} ^/nuforum/index\.html
RewriteRule (.*) /nuforum/index.php [L]
RewriteCond %{REQUEST_URI} ^/nuforum/category([0-9]*)\.html
RewriteRule (.*) /nuforum/index.php?c=%1 [L]
RewriteCond %{REQUEST_URI} ^/nuforum/forum([0-9]*)-([0-9]*)-([0-9]*)\.html
RewriteRule (.*) /nuforum/viewforum.php?f=%1&topicdays=%2&start=%3 [L]
RewriteCond %{REQUEST_URI} ^/nuforum/forum([0-9]*)-([0-9]*)\.html
RewriteRule (.*) /nuforum/viewforum.php?f=%1&start=%2 [L]
RewriteCond %{REQUEST_URI} ^/nuforum/forum([0-9]*)-mark\.html
RewriteRule (.*) /nuforum/viewforum.php?f=%1&mark=topics [L]
RewriteCond %{REQUEST_URI} ^/nuforum/forum([0-9]*)\.html
RewriteRule (.*) /nuforum/viewforum.php?f=%1 [L]
RewriteCond %{REQUEST_URI} ^/nuforum/ptopic([0-9]*)\.html
RewriteRule (.*) /nuforum/viewtopic.php?t=%1&view=previous [L]
RewriteCond %{REQUEST_URI} ^/nuforum/ntopic([0-9]*)\.html
RewriteRule (.*) /nuforum/viewtopic.php?t=%1&view=next [L]
RewriteCond %{REQUEST_URI} ^/nuforum/ftopic([0-9]*)-([0-9]*)-([a-zA-Z]*)-([0-9]*)-([a-zA-Z0-9]*)\.html
RewriteRule (.*) /nuforum/viewtopic.php?t=%1&start=%2&postdays=%3&postorder=%4&highlight=%5 [L]
RewriteCond %{REQUEST_URI} ^/nuforum/ftopic([0-9]*)-([0-9]*)-([a-zA-Z]*)-([0-9]*)\.html
RewriteRule (.*) /nuforum/viewtopic.php?t=%1&postdays=%2&postorder=%3&start=%4 [L]
RewriteCond %{REQUEST_URI} ^/nuforum/ftopic([0-9]*)-([0-9]*)\.html
RewriteRule (.*) /nuforum/viewtopic.php?t=%1&start=%2 [L]
RewriteCond %{REQUEST_URI} ^/nuforum/ftopic([0-9]*)\.html
RewriteRule (.*) /nuforum/viewtopic.php?t=%1 [L]
RewriteCond %{REQUEST_URI} ^/nuforum/fpost([0-9]*)\.html
RewriteRule (.*) /nuforum/viewtopic.php?p=%1 [L]
RewriteCond %{REQUEST_URI} ^/nuforum/post-newtopic-([0-9]*)\.html
RewriteRule (.*) /nuforum/posting.php?mode=newtopic&f=%1 [L]
RewriteCond %{REQUEST_URI} ^/nuforum/post-reply-([0-9]*)\.html
RewriteRule (.*) /nuforum/posting.php?mode=reply&t=%1 [L]
RewriteCond %{REQUEST_URI} ^/nuforum/post-([a-z]*)-([0-9]*)\.html
RewriteRule (.*) /nuforum/posting.php?mode=%1&p=%2 [L]
RewriteCond %{REQUEST_URI} ^/nuforum/album\.html
RewriteRule (.*) /nuforum/album.php [L]
RewriteCond %{REQUEST_URI} ^/nuforum/albumpic([0-9]*)-([a-z]*)\.html
RewriteRule (.*) /nuforum/album_page.php?pic_id=%1&mode=%2 [L]
RewriteCond %{REQUEST_URI} ^/nuforum/albumpic([0-9]*)\.html
RewriteRule (.*) /nuforum/album_page.php?pic_id=%1 [L]
RewriteCond %{REQUEST_URI} ^/nuforum/palbum\.html
RewriteRule (.*) /nuforum/album_personal_index.php [L]
RewriteCond %{REQUEST_URI} ^/nuforum/palbum([0-9]*)\.html
RewriteRule (.*) /nuforum/album_personal.php?user_id=%1 [L]
RewriteCond %{REQUEST_URI} ^/nuforum/profile([0-9]*)\.html
RewriteRule (.*) /nuforum/profile.php\?mode=viewprofile&u=%1 [L]
RewriteCond %{REQUEST_URI} ^/nuforum/search-author-(.*)\.html
RewriteRule (.*) /nuforum/search.php\?search_author=%1 [L]
RewriteCond %{REQUEST_URI} ^/nuforum/search-([0-9]*)-([0-9]*)\.html
RewriteRule (.*) /nuforum/search.php\?search_id=%1&start=%2 [L]
RewriteCond %{REQUEST_URI} ^/nuforum/search-([a-zA-Z]*)\.html
RewriteRule (.*) /nuforum/search.php\?search_id=%1 [L]
RewriteCond %{REQUEST_URI} ^/nuforum/privmsg-([a-zA-Z]*)-([0-9]*)\.html
RewriteRule (.*) /nuforum/privmsg.php\?mode=%1&u=%2 [L]
RewriteCond %{REQUEST_URI} ^/nuforum/privmsg-([a-zA-Z]*)\.html
RewriteRule (.*) /nuforum/privmsg.php\?folder=%1 [L]
RewriteCond %{REQUEST_URI} ^/nuforum/register\.html
RewriteRule (.*) /nuforum/profile.php\?mode=register&agreed=true [L]
RewriteCond %{REQUEST_URI} ^/nuforum/profile-([a-zA-Z0-9]*)\.html
RewriteRule (.*) /nuforum/profile.php\?mode=%1 [L]
RewriteCond %{REQUEST_URI} ^/nuforum/map-([0-9]*)\.html
RewriteRule (.*) /nuforum/map.php\?highlight=%1 [L]
RewriteCond %{REQUEST_URI} ^/nuforum/map\.html
RewriteRule (.*) /nuforum/map.php [L]
RewriteCond %{REQUEST_URI} ^/nuforum/faq\.html
RewriteRule (.*) /nuforum/faq.php [L]
RewriteCond %{REQUEST_URI} ^/nuforum/search\.html
RewriteRule (.*) /nuforum/search.php [L]
RewriteCond %{REQUEST_URI} ^/nuforum/memberlist\.html
RewriteRule (.*) /nuforum/memberlist.php [L]
RewriteCond %{REQUEST_URI} ^/nuforum/groups\.html
RewriteRule (.*) /nuforum/groupcp.php [L]
RewriteCond %{REQUEST_URI} ^/nuforum/report\.html
RewriteRule (.*) /nuforum/report.php [L]
RewriteCond %{REQUEST_URI} ^/nuforum/online\.html
RewriteRule (.*) /nuforum/viewonline.php [L]
Code: Alles auswählen
//
// start Short URL implementation [larsneo]
//
// 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\?mark=forums"|',
$prefix . '(?<!/)index.php"|',
$prefix . '(?<!/)index.php\?c=([0-9]*)"|',
$prefix . '(?<!/)viewforum.php\?f=([0-9]*)&(?:amp;)topicdays=0&(?:amp;)start=0"|',
$prefix . '(?<!/)viewforum.php\?f=([0-9]*)&(?:amp;)topicdays=0&(?:amp;)start=([0-9]*)"|',
$prefix . '(?<!/)viewforum.php\?f=([0-9]*)&(?:amp;)topicdays=([0-9]*)&(?:amp;)start=([0-9]*)"|',
$prefix . '(?<!/)viewforum.php\?f=([0-9]*)&(?:amp;)mark=topics"|',
$prefix . '(?<!/)viewforum.php\?f=([0-9]*)"|',
$prefix . '(?<!/)viewtopic.php\?t=([0-9]*)&(?:amp;)highlight="|',
$prefix . '(?<!/)viewtopic.php\?t=([0-9]*)&(?:amp;)view=previous"|',
$prefix . '(?<!/)viewtopic.php\?t=([0-9]*)&(?:amp;)view=next"|',
$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;)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"|',
$prefix . '(?<!/)viewtopic.php\?t=([0-9]*)&(?:amp;)start=([0-9]*)"|',
$prefix . '(?<!/)viewtopic.php\?t=([0-9]*)"|',
$prefix . '(?<!/)viewtopic.php\?p=([0-9]*)&(?:amp;)highlight=#([0-9]*)"|',
$prefix . '(?<!/)viewtopic.php\?p=([0-9]*)#([0-9]*)"|',
$prefix . '(?<!/)posting.php\?mode=newtopic&(?:amp;)f=([0-9]*)"|',
$prefix . '(?<!/)posting.php\?mode=reply&(?:amp;)t=([0-9]*)"|',
$prefix . '(?<!/)posting.php\?mode=([a-z]*)&(?:amp;)p=([0-9]*)"|',
$prefix . '(?<!/)album.php"|',
$prefix . '(?<!/)album_personal_index.php"|',
$prefix . '(?<!/)album_personal.php\?user_id=([0-9]*)"|',
$prefix . '(?<!/)profile.php\?mode=viewprofile&(?:amp;)u=([0-9]*)"|',
$prefix . '(?<!/)search.php\?search_author=([[:alnum:]%+\.]+)"|',
$prefix . '(?<!/)search.php\?search_id=([0-9]*)&(?:amp;)start=([0-9]*)"|',
$prefix . '(?<!/)search.php\?search_id=([a-zA-Z]*)"|',
$prefix . '(?<!/)privmsg.php\?mode=([a-zA-Z]*)&(?:amp;)u=([0-9]*)"|',
$prefix . '(?<!/)privmsg.php\?folder=([a-zA-Z]*)"|',
$prefix . '(?<!/)profile.php\?mode=register&(?:amp;)agreed=true"|',
$prefix . '(?<!/)profile.php\?mode=([0-9a-zA-Z]*)"|',
$prefix . '(?<!/)map.php\?highlight=([0-9]*)"|',
$prefix . '(?<!/)map.php"|',
$prefix . '(?<!/)faq.php"|',
$prefix . '(?<!/)search.php"|',
$prefix . '(?<!/)memberlist.php"|',
$prefix . '(?<!/)groupcp.php"|',
$prefix . '(?<!/)report.php"|',
$prefix . '(?<!/)viewonline.php"|',
);
$urlout = array(
'"index-mark.html"',
'"index.html"',
'"category\\1.html"',
'"forum\\1.html"',
'"forum\\1-\\2.html"',
'"forum\\1-\\2-\\3.html"',
'"forum\\1-mark.html"',
'"forum\\1.html"',
'"ftopic\\1.html"',
'"ptopic\\1.html"',
'"ntopic\\1.html"',
'"ftopic\\1.html"',
'"ftopic\\1.html"',
'"ftopic\\1-\\2.html"',
'"ftopic\\1-\\2-\\3-\\4.html"',
'"ftopic\\1.html"',
'"ftopic\\1-\\2.html"',
'"ftopic\\1.html"',
'"fpost\\1.html#\\2"',
'"fpost\\1.html#\\2"',
'"post-newtopic-\\1.html"',
'"post-reply-\\1.html"',
'"post-\\1-\\2.html"',
'"album.html"',
'"palbum.html"',
'"palbum\\1.html"',
'"profile\\1.html"',
'"search-author-\\1.html"',
'"search-\\1-\\2.html"',
'"search-\\1.html"',
'"privmsg-\\1-\\2.html"',
'"privmsg-\\1.html"',
'"register.html"',
'"profile-\\1.html"',
'"map-\\1.html"',
'"map.html"',
'"faq.html"',
'"search.html"',
'"memberlist.html"',
'"groups.html"',
'"report.html"',
'"online.html"',
);
$s = preg_replace($urlin, $urlout, $s);
return $s;
}
//
// end Short URL implementation [larsneo]
//
EDIT:
01.04.05 .htaccess Syntax optimiert
13.03.06 Link zur Google Sitemap hinzugefügt