PHP output_reset_rewrite_vars() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
Output Control

Definition

In PHP, output_reset_rewrite_vars() removes all rewrite variables previously stored by output_add_rewrite_var().

After a reset, later HTML flushed through the rewriter no longer receives those name/value pairs. Use it when a token should apply only to part of the output, or when you want to clear rewriter state.

Syntax

Call output_reset_rewrite_vars() with the values you need. Start with this line.

PHP
$ok = output_reset_rewrite_vars();
CallWhat it does
output_reset_rewrite_vars()Clears rewrite vars; returns true on success.
output_add_rewrite_var('x', '1'); output_reset_rewrite_vars()Adds a var, then clears it.
ob_flush()Often used between rewritten and non-rewritten sections.

Since PHP 7.1, this reset targets the dedicated output_add_rewrite_var() rewriter buffer, not session transparent-sid settings. Pair adds, flushes, and resets carefully so each section of HTML gets the query pairs you intend.

Library declarations
PHP
output_reset_rewrite_vars(): bool

Parameters

ParameterDescription
—This function takes no parameters.

Return Value

Return ValueDescription
booltrue on success, false on failure.

PHP Examples

Example 1 — Rewrite Then Reset

Add a rewrite var, flush one link, reset, then print a second link without the query pair.

PHP
<?php
ini_set('url_rewriter.tags', 'a=href');
output_add_rewrite_var('var', 'value');
echo '<a href="file.php">link</a>', PHP_EOL;
ob_flush();
output_reset_rewrite_vars();
echo '<a href="file.php">link</a>', PHP_EOL;

How It Works

  1. A rewrite var is stored and URL-Rewriter is active.
  2. The first link is flushed and rewritten with ?var=value.
  3. output_reset_rewrite_vars() clears that pair.
  4. The second link prints without the extra query parameter.

Example 2 — Reset Return Value

Call the reset function and print whether it reported success.

PHP
<?php
output_add_rewrite_var('tmp', '1');
$ok = output_reset_rewrite_vars();
echo $ok ? "reset-ok" : "reset-failed", PHP_EOL;

How It Works

  1. A temporary rewrite var is added.
  2. output_reset_rewrite_vars() clears it.
  3. The function returns true on success.
  4. We print a short status label.

Example 3 — Clear Before More Output

Show handlers after an add, then reset and continue with a plain message.

PHP
<?php
output_add_rewrite_var('k', 'v');
$during = ob_list_handlers();
output_reset_rewrite_vars();
echo $during[0], PHP_EOL;
echo "after-reset", PHP_EOL;

How It Works

  1. Adding a rewrite var activates URL-Rewriter.
  2. We remember the handler name from ob_list_handlers().
  3. output_reset_rewrite_vars() clears the stored variables.
  4. A plain status line prints afterward.

Frequently Asked Questions

It removes rewrite name/value pairs previously added with output_add_rewrite_var().
It clears the rewrite variables. Buffer/handler lifetime can still depend on how the URL-Rewriter was started and flushed in that request.
When only part of the page should receive the extra query pairs, flush the rewritten section first, then reset before printing more HTML.
true on success, false on failure.
Since PHP 7.1 it targets the dedicated output_add_rewrite_var() rewriter, not the older shared session transparent-sid buffer.

Back to Output Control Functions

Browse all PHP output control function tutorials.

Output Control functions →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful