Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7980655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:08:28+00:00 2026-06-04T10:08:28+00:00

I am trying to rewrite my URLs in PHP using the output buffer. Ideally

  • 0

I am trying to rewrite my URLs in PHP using the output buffer. Ideally this is so in my source I can keep my links as example.com/index.php?action=123;sa=456;sa2=789 but when outputted to the browser it rewrites as example.com/123/456/789 It seems to be working but when it gets to the “sa2” rewriting the output buffer tends to break occasionally and all the browser sees is a blank white page. When the page loads it starts an output buffer with gzip and then an output buffer with a rewrite callback. Here is my 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 to handle the rewriting

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]

This looks more and more like a PHP output buffer problem I just cannot seem to find what I am doing wrong. Any help is greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T10:08:30+00:00Added an answer on June 4, 2026 at 10:08 am

    Take care of this piece of code because based on the php version you use the buffer string sent to the rewrite function can contain only a chunk of the whole buffer (breaking the regular expression logic). You must force the chuck_size optional parameter to zero (in php version 5.4 and lower the default chuck size is 4096 bytes)

    Take a look at the documentation about ob_start:

    http://es.php.net/manual/en/function.ob-start.php

    This is probably the reason why this code “breaks occasionally”

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying use mod_rewrite to rewrite URLs from the following: http://www.site.com/one-two-file.php to http://www.site.com/one/two/file.php The
I'm trying to rewrite a url of this: http://www.foo.com/bar/baz to index.php?q=$1&d=baz Where bar is
I'm trying to add a trailing slash to urls using PHP. It can't be
Background Trying to recreate StackOverflow-style pretty URLs using Apache's mod rewrite and PHP. Problem
Ok, this is driving me nuts... I'm trying to rewrite my urls like this:
I'm trying to rewrite URLs to a generic show_page.php script, but I'm having trouble
I'm trying to get .htaccess to rewrite urls for my site. For example: /Lessons/PhrasalVerbs/PVList/bringup
i'm trying to rewrite my urls to goto a single php file: RewriteRule ^dir/(?:(?!style|js).)*$
I am trying to setup a mod rewrite rule to change urls like: http://www.site.com/play/4435
I am trying to rewrite my urls to go from /controller/method to index.php?/controller/method, and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.