.htaccess rewrite url with get parameter

后端 未结 1 1044
Happy的楠姐
Happy的楠姐 2020-12-11 08:00

this is my first time to try .htaccess

this is what i want.

example.com/account/blitzen12 -> example.com/account/index.php?id=10&name=blitzen1         


        
相关标签:
1条回答
  • 2020-12-11 08:34

    The "10" or the id, isn't part of the URL:

    example.com/account/blitzen12
    

    So you can't rewrite it into another URL, can't pull it out of thin air. You'll either need to just serve the page without an "id" (and pull it out of the database using the "name") or embed it in the URL without the query string, something like:

    example.com/account/10/blitzen12
    

    then you'd be able to rewrite it using:

    Options +FollowSymLinks  
    RewriteEngine On 
    
    RewriteRule ^account/([0-9]+)/(.*)$ ./account/index.php?page=account&id=$1&name=$2 [L,NC]
    
    0 讨论(0)
提交回复
热议问题