PHP When rewrite pages urls how to remove or redirect category.php?cat_id=2 urls to rewrited urls?

前端 未结 2 1623
再見小時候
再見小時候 2021-01-26 12:04

I am using this URL rewriting with PHP The Folder structure for rewriting the URLs. I am done it is working fine but after rewrite the URLs then ok now i have two URLs one is si

2条回答
  •  半阙折子戏
    2021-01-26 12:39

    Here is how the referred code example supposed to work:

    product-category.php

     "/product-category\\.php\\?cat_id=(?'category'\\d+)"
    );
    
    $uri = $_SERVER['REQUEST_URI'];
    $uri = urldecode( $uri );
    
    foreach ( $rules as $action => $rule ) {
        if ( preg_match( '#'.$rule.'#', $uri, $params ) ) {
            include( INCLUDE_DIR . $action . '.php' );
            exit();
        }
    }
    

    redirect-category.php

     'men-items'
    );
    header("Location: " . preg_replace( '#'.$rule.'#', "/product_category/{$categories[$params['category']]}/", $uri ));
    

提交回复
热议问题