budun Posted April 16, 2010 Share Posted April 16, 2010 Hello, I am using SMF 2.0 RC3. I want to rewrite the SMF URLs in the following way: index.php?topic=369616.0 >> index.php?t=369616 index.php?action=profile;u=53626 >> index.php?u=53626 I think I should be editing the last part of QueryString.php file, probably $buffer. This is the original code: // Rewrite URLs to include the session ID. function ob_sessrewrite($buffer) { global $scripturl, $modSettings, $user_info, $context; // If $scripturl is set to nothing, or the SID is not defined (SSI?) just quit. if ($scripturl == '' || !defined('SID')) return $buffer; // Do nothing if the session is cookied, or they are a crawler - guests are caught by redirectexit(). This doesn't work below PHP 4.3.0, because it makes the output buffer bigger. // !!! smflib if (empty($_COOKIE) && SID != '' && empty($context['browser']['possibly_robot']) && @version_compare(PHP_VERSION, '4.3.0') != -1) $buffer = preg_replace('/"' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', '"' . $scripturl . '?' . SID . '&', $buffer); // Debugging templates, are we? elseif (isset($_GET['debug'])) $buffer = preg_replace('/(?<!<link rel="canonical" href=)"' . preg_quote($scripturl, '/') . '\\??/', '"' . $scripturl . '?debug;', $buffer); // This should work even in 4.2.x, just not CGI without cgi.fix_pathinfo. if (!empty($modSettings['queryless_urls']) && (!$context['server']['is_cgi'] || @ini_get('cgi.fix_pathinfo') == 1 || @get_cfg_var('cgi.fix_pathinfo') == 1) && ($context['server']['is_apache'] || $context['server']['is_lighttpd'])) { // Let's do something special for session ids! if (defined('SID') && SID != '') $buffer = preg_replace('/"' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&))((?:board|topic)=[^#"]+?)(#[^"]*?)?"/e', "'\"' . \$scripturl . '/' . strtr('\$1', '&;=', '//,') . '.html?' . SID . '\$2\"'", $buffer); else $buffer = preg_replace('/"' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?"/e', "'\"' . \$scripturl . '/' . strtr('\$1', '&;=', '//,') . '.html\$2\"'", $buffer); } // Return the changed buffer. return $buffer; } I tried something like: $buffer = strtr($buffer, "topic", "t"); This doesn't change anything in the URLs. Should I be using preg_replace instead of strtr? I will be pleased if someone could give an idea. Thanks. Quote Link to comment Share on other sites More sharing options...
katierosy Posted April 20, 2010 Share Posted April 20, 2010 It is good to use .htaccess URLrewrite method here Quote Link to comment Share on other sites More sharing options...
budun Posted April 23, 2010 Author Share Posted April 23, 2010 Thank you for your interest. As far as I know, Apache mod_rewrite (in .htaccess file) is URL redirection. So, I am supposed to direct the old URL's to the new ones in .htaccess file after I change the way SMF codes URLs. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.