One problem with adding the $ at the end of that one parameter is that if there is a link "saved" or accessed that perhaps contains a zenId or has some other parameter on the uri, then a redirect will not occur (strengthening DrByte's recommendation to internally perform the redirect instead of trying to review/validate any possible combination of URIs that might be seen); however, in attempt to account for such on the URI and using an htaccess, might I suggest the following modification/use:
Code:
RewriteCond %{QUERY_STRING} ^(main_page=page&(.*)$|(.*)&main_page=page&(.*)$|(.*)&main_page=page$) [NC]
RewriteCond %{QUERY_STRING} ^(id=52&(.*)$|(.*)&id=52&(.*)$|(.*)&id=52$) [NC]
RewriteRule ^index\.php(.*) /blog/fun-run? [L,R=301]
What this does is support the main_page parameter being at the front, middle or end of the QUERY_STRING *AND* the id being at the front, middle or end (obviously both can not be at the front nor both at the end) of the string. Problem with this also is if say the id parameter is on the uri more than once:
Code:
index.php?main_page=page&id=2&id=52
Then it will still redirect (id=52 is present) even though if using the ZC "redirect", ZC would evaluate the uri as being applicable to id=2 and would not redirect...
To provide a solution that does not require modification of the existing code and therefore a need to be modified in a rebuilt store (but would require copying over to a new installation) the following could be used:
a new file to be loaded into or created in
includes/classes/observers
with the filename possibly:
auto.redirect_specific_ez_pages.php
that has the following content:
Code:
<?php
/**
* This redirects the designated ez-Pages to the chosen location
* @copyright mc12345678 2018 https://mc12345678.com
* @version applicable to ZC 1.5.3 and later. Earlier requires an includes/auto_loaders config.xxx file to invoke this auto.redirect_specific_ez_pages.php file as an observer class
**/
class zcObserverRedirectSpecificEzPages extends base {
function __construct() {
$attachThis = array();
$attachThis[] = 'NOTIFY_HEADER_START_EZPAGE';
$this->attach($this, $attachThis);
}
/**
* Camelized Notifier that is available in ZC 1.5.3 and above and is called when notifier NOTIFY_HEADER_START_EZPAGE is encountered.
* @parameter &$callingClass this modifiable variable provides access to the class that initiated the request.
* @parameter $notifier this contains the string of the name of the notifier that led to executing this function.
**/
function updateNotifyHeaderStartEzPage(&$callingClass, $notifier) {
if (isset($_GET['page']) && (int)$_GET['page'] == 25) {
// Redirects to the identified location, replacing previous headers that may have been sent, using a 301 redirect code
header('Location: /blog/table-tennis-rules/', true, 301);
}
}
/**
* This is the generic observer function that is called if a camelized version of the attached notifier is not found. In versions of ZC pre-1.5.3, this is the
* function that is called for all observers. It is possible in version before ZC 1.5.3 to also receive a non-editable "array" of data. Non-editable meaning
* that changes made here are not carried back to where the notifier is present. The notifier identified here does not pass any additional data and also
* by ZC design is in the global scope of the code, therefore to modify anything presented in the header file, that variable could be made global here
* and its results would be passed back to the line "after" the invoking notifier.
* @parameter &$callingClass this modifiable variable provides access to the class that initiated the request.
* @parameter $notifier this contains the string of the name of the notifier that led to executing this function.
**/
function update(&$callingClass, $notifier) {
if ($notifier === 'NOTIFY_HEADER_START_EZPAGE') {
// Calls the internal class function that handles the request. This way the code is written in one place and changes can be made that are applicable
// to all versions of ZC in which this is ultimately executed.
$this->updateNotifyHeaderStartEzPage($callingClass, $notifier);
}
}
}
Bookmarks