我正在尝试使用输出缓冲区在 PHP 中重写我的 URL。理想情况下,在我的源代码中,我可以保留我的链接,example.com/index.php?action=123;sa=456;sa2=789
但是当输出到浏览器时,它会重写,因为example.com/123/456/789
它似乎正在工作,但是当它到达“sa2”时,重写输出缓冲区往往会偶尔中断,浏览器看到的是一个空白的白页。当页面加载时,它会使用 gzip 启动一个输出缓冲区,然后是一个带有重写回调的输出缓冲区。这是我的 php/.htaccess
<?php
if (!ob_start("ob_gzhandler"))
ob_start();
// Handle Rewriting of URLs
RewriteURLs();
function RewriteURLs()
{
// rewrite URLS from output buffer
function rewrite($buffer)
{
// pages
$buffer = preg_replace('/index.php\?page=(.*?)/is', "page/$1", $buffer);
// sub-sub-actions
$buffer = preg_replace('/index.php\?action=(.*?);sa=(.*?);sa2=(.*?)/is', "$1/$2/$3", $buffer);
// sub-actions
$buffer = preg_replace('/index.php\?action=(.*?);sa=(.*?)/is', "$1/$2", $buffer);
// actions
$buffer = preg_replace('/index.php\?action=(.*?)/is', "$1", $buffer);
// index.php removal
$buffer = preg_replace('/index.php/is', "", $buffer);
return $buffer;
}
// start for rewriting
ob_start('rewrite');
}
// rest of content/page loading.......
?>
.htaccess 处理重写
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
# Rules for: pages
RewriteRule ^page/([-_!~*'()$\w]+)/?$ index.php?page=$1 [L,QSA]
# Rules for sub-sub-actions
# /{action}/{subaction}/{subsubaction}/
RewriteRule ^([-_!~*'()$\w]+)/([-_!~*'()$\w]+)/([-_!~*'()$\w]+)/?$ index.php?action=$1;sa=$2;sa2=$3
# Rules for sub-actions
# /{action}/{subaction}/
RewriteRule ^([-_!~*'()$\w]+)/([-_!~*'()$\w]+)/?$ index.php?action=$1;sa=$2
# Rules for: actions
# /{action}/
RewriteRule ^([-_!~*'()$\w]+)/?$ index.php?action=$1 [L,QSA]
这看起来越来越像 PHP 输出缓冲区问题,我似乎无法找到我做错了什么。任何帮助是极大的赞赏。