W3docs

PHP output_reset_rewrite_vars() Function

Learn how PHP's output_reset_rewrite_vars() function clears all variables registered by the URL rewriter, with syntax, return values, and examples.

output_reset_rewrite_vars() is a built-in PHP function that clears every variable previously registered with the URL rewriter. The URL rewriter is the same mechanism PHP uses to forward values (most notably the session ID, when session.use_trans_sid is on) across page requests by appending them to URLs and injecting them into HTML forms. This function gives you back full control over that list — it removes everything you added with output_add_rewrite_var().

Note: This is a genuine PHP core function from the output-control extension. It has nothing to do with the $_GET superglobal or with the WordPress add_rewrite_var() API — those are unrelated.

What output_reset_rewrite_vars() Does

When you call output_add_rewrite_var('name', 'value'), PHP starts automatically appending name=value to every relative URL and adding a matching hidden field to every form on the rest of the page. Those variables stay active until output ends.

output_reset_rewrite_vars() stops that behavior immediately by emptying the rewriter's variable list. Any output produced after the call no longer carries the rewritten variables; output already sent is unaffected.

Syntax

output_reset_rewrite_vars(): bool
  • Parameters: none.
  • Return value: true on success, false on failure.

Basic Example

Add a variable, emit some output that uses it, then reset so the rest of the page is clean:

<?php
// Register a rewrite variable: every relative link/form below gets var=value
output_add_rewrite_var('var', 'value');

echo '<a href="page.php">This link carries the variable</a>';
// Rendered as: <a href="page.php?var=value">...</a>

// Clear all registered rewrite variables
output_reset_rewrite_vars();

echo '<a href="other.php">This link is left untouched</a>';
// Rendered as: <a href="other.php">...</a>

The first link is rewritten because the variable is active; the second is not, because output_reset_rewrite_vars() removed it.

When You Would Use It

  • Scoping a rewrite to part of a page. Use output_add_rewrite_var() at the top of a section and output_reset_rewrite_vars() at the bottom so links outside that section stay clean.
  • Switching variable sets. Reset before registering a different group of variables to avoid leftover values leaking through.
  • Disabling trans-SID locally. When PHP auto-adds the session ID to URLs, resetting the rewriter prevents the session ID from being appended to a specific set of links (for example, links pointing to an external domain).

Checking the Result

The return value tells you whether the reset succeeded:

<?php
output_add_rewrite_var('token', 'abc123');

if (output_reset_rewrite_vars()) {
    echo "Rewrite variables were cleared.\n";
} else {
    echo "Failed to clear rewrite variables.\n";
}
// Output: Rewrite variables were cleared.
FunctionPurpose
output_add_rewrite_var()Registers a variable the URL rewriter appends to URLs/forms.
ob_start()Starts output buffering, which the rewriter builds on.
ob_get_clean()Returns and discards the current output buffer.

For the bigger picture on how PHP manages generated output, see PHP Output Control. If your rewrite variables are session IDs, the PHP Sessions chapter explains where those values come from.

Conclusion

output_reset_rewrite_vars() is the counterpart to output_add_rewrite_var(): it wipes the URL rewriter's variable list so that subsequent output stops carrying automatically appended values. Reach for it whenever you need to scope or undo URL rewriting within a single request.

Practice

Practice
What does the PHP function output_reset_rewrite_vars() do?
What does the PHP function output_reset_rewrite_vars() do?
Was this page helpful?