缺少.htaccess代码的自定义网址

时间:2019-04-26 09:10:25

标签: php apache .htaccess

我想创建自定义SEO友好URL。第一条规则工作正常。但是另一个规则不起作用。我在htaccess文件中提到了所有问题 第1步工作正常,但第2、3、4、5步无效。我正在使用PHP 7.2和xampp服务器。

  <?php $category = mysqli_query($conn,"SELECT * from category  ORDER BY title ASC");
           while($row = mysqli_fetch_array($category))  {

            $title = $row['title'];
            $cat_id = $row['cat_id'];
            $title  = urldecode($title);  
            $title = str_replace(' ', '-', $title); 
            $url = '/' . urlencode($title) . '-' . urlencode($cat_id);
        ?>
        <a href="<?php echo $url ?>"><button type="button" class="btn btn-warning">Read More..</button></a>

.htaccess

       RewriteEngine On
       RewriteCond %{SERVER_PORT} 80
       RewriteRule ^(.*)$ https://www.proyellowpage.com/$1 [R,L]
       RewriteCond %{REQUEST_FILENAME} !-f
       RewriteCond %{REQUEST_FILENAME} !-d

STEP-1工作正常

       #https://www.proyellowpage.com/show-subcategories.php?cat_id=$1
       RewriteRule (\d+)$ show-subcategories.php?cat_id=$1 [L]

STEP-2无法正常工作

      PHP code with a link
   <?php
    $cat_id=$_GET['cat_id']; 
    $subcat=$conn->query("SELECT * FROM sub_category WHERE cat_id='$cat_id'" );while($row=$subcat->fetch_array()){ 

        $title = $row['title'];

        $sub_cat_id = $row['sub_cat_id'];

        $title  = urldecode($title);  

        $title = str_replace(' ', '-', $title); 

        $sub_url = '/' . urlencode($title) . '-' . urlencode($sub_cat_id);
    ?>

<a href="<?php echo $sub_url ?>" class=""><button class="btn btn-primary">View More</button></a>


       #https://www.proyellowpage.com/show-childcategories.php?sub_cat_id=$1

这里缺少代码?

       RewriteRule (\d+)$ show-childcategories.php?sub_cat_id=$1 [L] ????
       #custom URL -> https://www.proyellowpage.com/categories/computer-keyboard-1

STEP-3无法正常工作

       #https://www.proyellowpage.com/search-result.php?p_id=$1
       #the missing code here?
       RewriteRule ^search/([a-zA-Z0-9-]+)$ search-result.php?p_id=$1 [L] ?????
       #custom URL -> https://www.proyellowpage.com/search/hardware-1

STEP-4无法正常工作

       #https://www.proyellowpage.com/category.php?inventory_id=$1
       #the missing code here?
       RewriteRule ^inventory/([a-zA-Z0-9-]+)$ category.php?inventory_id=$1 [L] ????
       #custom URL -> https://www.proyellowpage.com/computer-shop-1

STEP-5无法正常工作

       #https://www.proyellowpage.com/search-inventory.php?city=1&keyword=Health-care&search=
       #the missing code here?
       RewriteRule (\d+)$ ?????????=$1 [L]
       #custom URL -> https://www.proyellowpage.com/1-Health-care

0 个答案:

没有答案