Skip to content
Advertisement

how to change the way the url looks but keep the function

How do I change my URL’s function for calling up on pages? Here’s an example: https://exaplesitename.com/index.php?id=21 What it looks like now but I want it to be something like this: https://exaplesitename.com/Entertainment This is the navigation code:

<?php
function find_parent_categories($options=[]) {
    global $db;

    $Active = $options['Active'] ?? 'false';

    $sql = "SELECT * FROM Parent_Categories ";
    if($Active){
        $sql .= "WHERE Active = true ";
    }
    $sql .= "ORDER BY Category_Order ASC";
    $result = mysqli_query($db, $sql);
    confirm_result_set($result);
    return $result;
}

function find_categories($id_Category_Parent, $options=[]){
    global $db;

    $Active = $options['Active'] ?? 'false';

    $sql = "SELECT * FROM Categories ";
    $sql .= "WHERE id_Category_Parent='" . db_escape($db, $id_Category_Parent) . "' ";
    if($Active){
        $sql .= "AND Active = true ";
    }
    $sql .= "ORDER BY Category_Order ASC";
    $result = mysqli_query($db, $sql);
    confirm_result_set($result);
    return $result;
} ?>

<nav class="navbar fixed-top navbar-expand-lg bg-white navbar-custom">
    <a class="navbar-brand" href="<?php echo url_for('/index.php'); ?>">
        <img src="../../images/Logo1.png" alt="Nantucket" class="img-fixed"/>
    </a>
    <button class="navbar-toggler custom-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent1" aria-controls="navbarSupportedContent1" aria-expanded="false" aria-label="Toggle navigation">Menu
        <span class="navbar-toggler-icon"></span> 
    </button>
    <div class="collapse navbar-collapse" id="navbarSupportedContent1">
        <?php $nav_categories = find_parent_categories(['Active' => true]); ?>
        <ul class="navbar-nav mr-auto">
            <?php while($nav_category = mysqli_fetch_assoc($nav_categories)) { ?>
                <li class="nav-item dropdown">
                    <a class="nav-link dropdown-toggle" href="<?php echo url_for('index.php?id=' . h(u($nav_category['id']))); ?>" id="navbarDropdown1" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><?php echo h($nav_category['Category_Name']); ?></a>
                    <?php $nav_sub_categories = find_categories($nav_category[id], ['Active' => true]); ?>    
                    <ul class="dropdown-menu" aria-labelledby="navbarDropdown1"> 
                        <?php while($nav_sub_category = mysqli_fetch_assoc($nav_sub_categories)) { ?>   
                            <li>
                                <a class="dropdown-item" href="<?php echo url_for('index.php?id=' . h(u($nav_sub_category['id']))); ?>"> <?php echo h($nav_sub_category['Category_Name']); ?></a> 
                            </li>
                        <?php } //while $nav_sub_categories ?>
                    </ul>
                    <?php mysqli_free_result($nav_sub_categories); ?>
                    <?php mysqli_free_result($nav_categories); ?>
                </li>
            <?php } ?>
        </ul>
    </div>
</nav>

Thank you very much for any help and kindness.

Advertisement

Answer

Any change in url can be achieved by changing .htaccess file.

RewriteEngine On
RewriteRule   https://exaplesitename.com/Entertainment   https://exaplesitename.com/index.php?id=21

For more information about .htaccess please refer to:

https://www.smashingmagazine.com/2011/11/introduction-to-url-rewriting/

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement