.htaccess如何将未知文件夹名称重定向到它的父级但忽略子文件夹

时间:2018-04-19 16:38:10

标签: apache .htaccess redirect url-redirection

我必须重定向到父(索引)目录,但保持第二个子文件夹可用。第一个子文件夹也有许多未知的随机名称,如:

domain.com/puzzles/index/random-id15345/v01/
domain.com/puzzles/index/random-id26654/v02/
domain.com/puzzles/index/random-id36544/v03/

等等,人们应该能够访问这些URL而不是父母" random-ids"目录,这是未知的字符串。如果有人试图通过删除" v01 /"网址的一部分如此:

domain.com/puzzles/index/random-id36544/

它应该将它们重定向到索引:

domain.com/puzzles/index/

感谢。

1 个答案:

答案 0 :(得分:1)

您可以将此规则用作第一条规则:

<?php
$boletas_query = mysqli_query($datacenter, "
    SELECT * FROM ventas 
    WHERE documento = 'boleta' 
    ORDER BY id DESC LIMIT 1");

$boletas = array();

while ($boleta = mysqli_fetch_assoc($boletas)) {
    $boletas[] $boleta;
}


$facturas_query = mysqli_query($datacenter, "
    SELECT * FROM ventas WHERE documento = 'factura' 
    ORDER BY id DESC LIMIT 1");

$facturas = array();

while ($factura = mysqli_fetch_assoc($facturas)) {
    $facturas[] = $factura;
}


$notas_query = mysqli_query($datacenter, "
    SELECT * FROM ventas 
    WHERE documento = 'nota' 
    ORDER BY id DESC LIMIT 1");

$notas = array();


while ($nota = mysqli_fetch_assoc($notas)) {
    $notas[] = $nota;
}

foreach ($boletas as $boleta) {
    ?>
    <?php
    foreach ($facturas as $factura) {
        ?>
        <?php
        foreach ($notas as $nota) {
            ?>


            <select class="selects" > 
                <option value="3" data-price="
                <?php
                echo str_pad($boleta['folio'] + 1, 15, "0", STR_PAD_LEFT);
                ?>">
            boleta</option>
            <option value="4" data-price="
            <?php
            echo str_pad($factura['folio'] + 1, 15, "0", STR_PAD_LEFT);
            ?>">factura</option>
            <option value="5" data-price="
            <?php
            echo str_pad($nota['folio'] + 1, 15, "0", STR_PAD_LEFT);
            ?>">nota de venta</option>
        </select>

        <input type="text" class="inputs" 
        value="<?php
        echo str_pad($boleta['folio'] + 1, 15, "0", STR_PAD_LEFT);
        ?>">

        <?php
    }
}
}
?>