重定向PHP的位置
我正在尝试使用如下foreach将404重定向到/subcategory root: 例如:重定向PHP的位置,php,magento,Php,Magento,我正在尝试使用如下foreach将404重定向到/subcategory root: 例如: 如果404在子类别domain.com/helmet/whatever中,我会尝试发送到domain.com/helmet(helmet在西班牙语中是cascos) 一切正常,但当我试图重定向到我的主页的URL时,我的数组中没有任何单词,我无法重定向。Equipamento/Unsived moto是一个目录吗 如果是这样,即使您有目录的索引页,您也不能向其中添加.html,并且您应该将标题更改为:
- 如果404在子类别domain.com/helmet/whatever中,我会尝试发送到domain.com/helmet(helmet在西班牙语中是cascos)
一切正常,但当我试图重定向到我的主页的URL时,我的数组中没有任何单词,我无法重定向。Equipamento/Unsived moto是一个目录吗 如果是这样,即使您有目录的索引页,您也不能向其中添加.html,并且您应该将标题更改为:
<?php
$url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$find = array(
'equipamiento/impermeable-moto',
'equipamiento/ropa-termica-moto',
'equipamiento/ropa-accesorios',
'equipamiento/protecciones',
'equipamiento/electronica-moto',
'equipamiento/mono-moto',
'equipamiento/pantalon-moto',
'equipamiento/botas-moto',
'equipamiento/chaquetas-moto',
'equipamiento/cascos-moto',
'equipamiento/equipaje',
'equipamiento/guantes-moto',
'equipamiento',
'recambios/accesorios',
'recambios/lubricantes',
'recambios/sistema-frenado-moto',
'recambios/suspension',
'recambios/baterias-moto',
'recambios/baterias-moto',
'recambios'
);
foreach ($find as $v) {
if (stripos($url, $v) !== false) {
Header( 'HTTPS/1.1 301 Moved Permanently');
Header( 'Location: https://example.com/'.$v.'.html');
exit;
break;
}
}
?>
如果它不是一个目录,您的示例将不适用,因为domain.com/helmet/whatever位于/helmet/目录中。如果您正在寻找具体的URL进行重定向,您可以直接在后端执行此操作。建议的方法是: 马根托1 马根托2号 另一方面,如果您希望应用一些逻辑,如您所说的子类别,也许您可以开发一个模块 此模块可能具有下一个逻辑:
如果$URL==404
然后$priorURL=$URL-$URL\u lastsslash
如果$priorURL是类别,则重定向
关于。为什么不在
foreach
循环之后添加另一个重新定位?像这样,只有在循环内部没有发生重新定位的情况下才会执行重定向。您能否澄清在哪种情况下不会发生重定向,以及您试图解决的问题?
header( 'Location: https://example.com/'.$v);