modX.sendRedirect
Last updated Oct 14th, 2026 | Page history | Improve this page | Report an issue
Support the team building MODX with a monthly donation.
The budget raised through OpenCollective is transparent, including payouts, and any contributor can apply to be paid for their work on MODX.
Backers
Budget
$194 per month—let's make that $500!
Learn moremodX::sendRedirect¶
Sends a redirect to the specified URL using the specified method.
Syntax¶
void sendRedirect (string $url, [array|boolean $options = false], [string $type = ''], [string $responseCode = ''])
$url must be a valid URL — modX::makeUrl builds one. An empty URL is not redirected: the method writes an error to the log and returns without sending a header.
$type and $responseCode are deprecated since 2.0.5 in favour of the type and responseCode keys of $options. 3.x still accepts them, but each use writes a deprecation record to the log — pass the values in the $options array instead.
$options accepts an array (or a boolean, treated as the count_attempts flag) with one or more of the following key/value pairs:
type, one of the following (REDIRECT_HEADERis the default):REDIRECT_REFRESH- Uses the header refresh methodREDIRECT_META- Sends a META HTTP-EQUIV=“Refresh” tag to the outputREDIRECT_HEADER- Uses the header location method
responseCodethe full HTTP status line, not just301or302. Defaults toHTTP/1.1 302 Moved Temporarily; passHTTP/1.1 301 Moved Permanentlyfor a permanent redirect.count_attempts(boolean) appends an?err=Ncounter to the URL to break redirect loops. After 3 attempts — the limit is hard-coded — the redirect is treated as fatal: a FATAL entry is logged and a fatal error page is sent.preserve_request(boolean) when set, the current request is preserved (seemodRequest::preserveRequest) before the redirect, so the referrer survives.
Examples¶
Redirect to the Resource with ID 54.
$url = $modx->makeUrl(54);
$modx->sendRedirect($url);
Send a redirect to modx.com via the META HTTP-EQUIV refresh tag.
$modx->sendRedirect('https://modx.com',array('type' => 'REDIRECT_META'));
Send the 301 Moved Permanently response code instead of the default 302 Moved Temporarily.
$modx->sendRedirect('https://modx.com',array('responseCode' => 'HTTP/1.1 301 Moved Permanently'));
See Also¶
Support the team building MODX with a monthly donation.
The budget raised through OpenCollective is transparent, including payouts, and any contributor can apply to be paid for their work on MODX.
Backers
Budget
$194 per month—let's make that $500!
Learn more










