How can I use in .htaccess?

前端 未结 3 952
闹比i
闹比i 2021-01-17 03:23

I want to change from this address:

www.domain.com/game.php?id=1

to somthing like that:

www.domain.com/game/1/THE-NAME-OF-T         


        
3条回答
  •  有刺的猬
    2021-01-17 04:16

    Probably the best way is to redirect page to correct url like code below:(work for me)

    if (isset($_GET['id'])) {
    $script_url = "http://localhost/scripts/myscripts/";
      $row = dbgetrow("SELECT * FROM games WHERE id = %s",$_GET['id']);
      if ($row) {
        Header( "HTTP/1.1 301 Moved Permanently" ); 
        Header( "Location: ".$script_url."/game/".$row['id']."/".seo_title($row['name'])); 
      } else {
        Header( "HTTP/1.1 404 Not found" ); 
      }
    }
    

    and in .htaccess file you can also set RewriteBase to somethings like RewriteBase / or RewriteBase /YOUR_SCRIPT_PATH_WITHOUT_HOST_NAME/

    also see Apache Doc

提交回复
热议问题