phpBB Mod Rewrite

Tips and help with HTML, CSS, JavaScript, and site development.
Post Reply
User avatar
ccb056
Site Administrator
Posts: 981
Joined: January 14th, 2004, 11:36 pm
Location: Texas
Contact:

phpBB Mod Rewrite

Post by ccb056 »

http://www.bandofgonzos.com/phpbb/viewtopic.php?t=2695

Code: Select all

[i]
[/i]#
#-----[ OPEN ]------------------------------------------
#

includes/page_header.php

#
#-----[ FIND ]------------------------------------------
#

$template->set_filenames(array(
    'overall_header' => ( empty($gen_simple_header) ) ? 'overall_header.tpl' : 'simple_header.tpl')
);

#
#-----[ AFTER, ADD  ]------------------------------------------
#

ob_start();


function make_url_friendly($url)
{

    $url = strtolower($url);

    $find = array(' ',
            '&',
            '\r\n',
            '\n',
            '/',
            '\\',
            '+');

    $url = str_replace ($find, '-', $url);

    $find = array(' ',
            'é',
            'è',
            'ë',
            'ê');
     
    $url = str_replace ($find, 'e', $url);
     
    $find = array(' ',
            'ó',
            'ò',
            'ô',
            'ö');
     
    $url = str_replace ($find, 'o', $url);
     
    $find = array(' ',
            'á',
            'à',
            'â',
            'ä');
     
    $url = str_replace ($find, 'a', $url);
     
    $find = array(' ',
            'í',
            'ì',
            'î',
            'ï');
     
    $url = str_replace ($find, 'i', $url);
     
    $find = array(' ',
            'ú',
            'ù',
            'û',
            'ü');
     
    $url = str_replace ($find, 'u', $url);
     
    $find = array('/[^a-z0-9\-<>]/',
            '/[\-]+/',
            '/<[^>]*>/');

    $repl = array('',
            '-',
            '');

    $url =  preg_replace ($find, $repl, $url);

    return $url;

}


function rewrite_urls($content)
{

    function if_query($amp)
    {

        if($amp != '')
        {
            return '?';
        }

    }

    $url_in = array('/(?<!\/)viewforum.php\?f=([0-9]+)((&)|(&)){0,1}([^>]+>)(.*? )<\/a>/e',
            '/(?<!\/)viewtopic.php\?p=([0-9]+)((&)|(&)){0,1}([^>]+>)(.*?)<\/a> /e',
            '/(?<!\/)viewtopic.php\?t=([0-9]+)((&)|(&)){0,1}([^>]+>)(.*?)<\/a> /e');

    $url_out = array("make_url_friendly('\\6') . '-vf\\1.html' . if_query('\\2') . stripslashes('\\5\\6') . '</a>'",
            "make_url_friendly('\\6') . '-vp\\1.html' . if_query('\\2') . stripslashes('\\5\\6') . '</a>'",
            "make_url_friendly('\\6') . '-vt\\1.html' . if_query('\\2') . stripslashes('\\5\\6') . '</a>'");

    $content = preg_replace($url_in, $url_out, $content);

    return $content;

}   

#
#-----[ OPEN ]------------------------------------------
#

includes/page_tail.php

#
#-----[ FIND ]------------------------------------------
#

if ( $do_gzip_compress )
{
    //
    // Borrowed from php.net!
    //
    $gzip_contents = ob_get_contents();
    ob_end_clean();

    $gzip_size = strlen($gzip_contents);
    $gzip_crc = crc32($gzip_contents);

    $gzip_contents = gzcompress($gzip_contents, 9);
    $gzip_contents = substr($gzip_contents, 0, strlen($gzip_contents) - 4);

    echo "\x1f\x8b\x08\x00\x00\x00\x00\x00";
    echo $gzip_contents;
    echo pack('V', $gzip_crc);
    echo pack('V', $gzip_size);
}

#
#-----[ REPLACE, WITH  ]------------------------------------------
#

if ( $do_gzip_compress )
{
    //
    // Borrowed from php.net!
    //
    $gzip_contents = ob_get_contents();
    ob_end_clean();
    echo rewrite_urls($contents);
    global $dbg_starttime;
     
    $gzip_size = strlen($gzip_contents);
    $gzip_crc = crc32($gzip_contents);

    $gzip_contents = gzcompress($gzip_contents, 9);
    $gzip_contents = substr($gzip_contents, 0, strlen($gzip_contents) - 4);

    echo "\x1f\x8b\x08\x00\x00\x00\x00\x00";
    echo $gzip_contents;
    echo pack('V', $gzip_crc);
    echo pack('V', $gzip_size);
}
else
{
    $contents = ob_get_contents();
    ob_end_clean();
    echo rewrite_urls($contents);
    global $dbg_starttime;
}
HTACCESS

Code: Select all

[i]
[/i]Options +FollowSymlinks

RewriteEngine On
#this may cause isues with subdirs and so I have not enabled it.
#RewriteBase /

RewriteRule [.]*-vf([0-9]*) viewforum.php?%{QUERY_STRING}&f=$1
RewriteRule [.]*-vp([0-9]*) viewtopic.php?%{QUERY_STRING}&p=$1
RewriteRule [.]*-vt([0-9]*) viewtopic.php?%{QUERY_STRING}&t=$1
The above code rewrites URLs for phpBB forums to display the topic's title.
Post Reply