...
Stores -> Configuration -> General -> Web -> Custom Rewrites
...
Settings
List of rewrites | Provide one rewrite per line in format: "{original_path}|{target_path}|{status_code}" |
Example
entry:
Code Block |
---|
/de_de/madchen/babys-gr.-50-92-/jacken-overalls/overalls.html|/de_de/madchen.html |
means:
http://magesuite.me/de_de/madchen/babys-gr.-50-92-/jacken-overalls/overalls.html
will redirect to:
http://magesuite.me/de_de/maedchen.html
Backend
Note |
---|
Backend documentation and general review is needed. |
List of rewrites
is placed in database in table core_config_data with pathweb/custom_rewrites/rewrites
Router
There is Router class with match method, which checks if there is a match for given url.
If not - nothing happens, if there is - url is redirect to given target
vendor/creativestyle/magesuite-url-rewrite/Controller/Router.php:39
Code Block |
---|
public function match(\Magento\Framework\App\RequestInterface $request)
{
$server = $request->getServer();
$requestUri = $server->get('ORIGINAL_URI') ? $server->get('ORIGINAL_URI') : $request->getRequestUri();
.....
$rewrite = $this->rewriteRepository->getRewrite($requestUri);
if($rewrite == null) {
return null;
}
$this->response->setRedirect($rewrite->getTargetUrl());
$this->response->setStatusCode($rewrite->getStatusCode());
.....
} |
Method getRewrite gets list of rewrites from configuration
Checks if there is entry for requested url, if yes - sets rewrite url as target url
vendor/creativestyle/magesuite-url-rewrite/Repository/RewriteRepository.php:35
Code Block |
---|
public function getRewrite($requestUri) {
$rewrites = $this->scopeConfig->getValue('web/custom_rewrites/rewrites', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
.....
$rewrites = explode(PHP_EOL, $rewrites);
foreach($rewrites as $rewrite) {
$rewrite = explode('|', $rewrite);
.....
$originalUrl = ltrim($rewrite[self::ORIGINAL_URL], '/');
$originalUrl = trim($originalUrl);
if($originalUrl != $requestUri) {
continue;
}
$targetRewrite = $this->rewriteFactory->create();
$targetRewrite->setTargetUrl($rewrite[self::TARGET_URL]);
$targetRewrite->setStatusCode($rewrite[self::STATUS_CODE] ?? self::DEFAULT_STATUS_CODE);
return $targetRewrite;
}
.....
} |
Frontend
There is no frontend part to document.