Redirect review pages to listing pages
- Thread started
- Last updated
What you’ll achieve
Redirect review detail URLs to their parent listing with a permanent HTTP 301 redirect.
My site
Send visitors who open an individual review page to the listing that was reviewed. The code uses HTTP 301, a permanent redirect that also tells search engines the page has moved. It opens the listing page without scrolling to that individual review.
Use this when a review URL should open its listing page. A robots.txt rule controls crawling. It does not redirect visitors or reliably remove an indexed URL from search results.
JReviews 6 Early Access
Redirect review detail URLs
Open Configuration > Early Access Settings and enable Discussion Pages. This switch supplies the review detail page used by the callback below.
Add the code below to forward the visitor before the individual review page appears.
Joomla. Save the code in templates/jreviews_overrides/hooks.php.
WordPress. Save the code in jreviews_overrides/hooks.php.
Start a new file with <?php. Add the example below without repeating the opening tag if the file already exists. Keep any existing hooks.
fwd_add_filter('jreviews:view_data:comments_detail', function (array $data): array {
$listing = $data['listing'] ?? null;
if (!$listing instanceof \JReviews\App\Models\Listing || !$listing->exists) {
return $data;
}
fwd_abort(fwd_redirect($listing->url, 301));
}, 20, 1);
The code uses JReviews' URL for the reviewed listing. If that listing is missing, it leaves JReviews to show its normal not-found response.
JReviews 5 and v6 Legacy
Add the code to your overrides
Use templates/jreviews_overrides/filters/filter_functions.php.
Use jreviews_overrides/filters/filter_functions.php.
Start a new file with <?php followed by defined('MVC_FRAMEWORK') or die;. Keep existing filters and add the example without repeating those lines.
Redirect review detail URLs to their listing
Disabling review discussions does not disable review detail pages. Visitors can still share those pages, and search engines can index them.
Add this filter to your override file above to redirect a review detail URL to its listing.
Clickfwd\Hook\Filter::add('before_theme_render_viewvars_discussions_review', function($viewVars, $params)
{
$url = cmsFramework::route($viewVars['listing']['Listing']['url']);
cmsFramework::redirect($url, 301);
die;
});
The code uses the reviewed listing's URL and sends the permanent redirect before showing the review page.
The example redirects the review detail page to the listing URL. It does not add an anchor that scrolls to the individual review.
Check the redirect and destination
Open the browser's developer tools and select Network. Open a published review detail URL. Select that review request and check Headers for status 301 and a Location value containing the listing URL. Confirm that the browser opens that listing without redirecting back to the review.