Apache friendly urls

后端 未结 3 1080
孤城傲影
孤城傲影 2020-12-22 07:56

I\'ve got a small CMS system written in PHP and running on Apache. The format of the URLs this CMS system uses/generates is:

/display.php?PageID=xxx where xxx is ju

相关标签:
3条回答
  • 2020-12-22 08:18

    Another way is filter by a dynamic php file with a mapping for pages or a routing strategy like frameworks like drupal code igniter .... and your URL will be like my-pages/about.html -> display.php?PageID=44 my-pages/products.html -> display.php?PageID=34

    and so on

    Here a suggestion for .htaccess file and the filter the action with this strategy

    --- .htaccess file ---- *RewriteEngine on

    RewriteRule ^my-pages/(.).html$ MY-URL.php [QSA,L,E]

    ---------------- MY-URL.php ---------

    <?php 
    
    $PREFIX = 'my-pages/'; //--- not used 
    $mapping=array(
            'about' => 44,
            'products' => 34
    );
    $pathinfo=   pathinfo( $_SERVER['REQUEST_URI'] );
    /*  $pathinfo['dirname']  ->  my-pages 
        $pathinfo['basename'] -> ???.html
        $pathinfo['extension']->  .html
    */
    $page = substr( $pathinfo['basename'] ,0,-5);
    
    
    if( isset( $mapping[$page] ){
             //  ---- redirect or include
             YUOR CODE HERE 
    }  
    else {
            //--- error 404
              YUOR CODE HERE  
    }
    
    
    ?>
    
    0 讨论(0)
  • 2020-12-22 08:22

    well putting something like

    RewriteEngine on
    
    RewriteRule ^about$  ./display.php?PageID=44
    RewriteRule ^products$ ./display.php?PageID=34
    

    in your .htaccess-file shouldn't be the big deal I think...

    0 讨论(0)
  • 2020-12-22 08:28

    URL Rewriting for Beginners is my favorite intro article to this, it should cover what you're looking for. In fact, the first actual example where you write a .htaccess file is almost identical to what you want.

    0 讨论(0)
提交回复
热议问题