How do I convert a PHP query string into a slash-based URL?

前端 未结 3 593
春和景丽
春和景丽 2020-12-10 06:45

I am a pretty skilled programmer, but when it comes to RegEx and rewriting, I am a total n00b. I want to convert a URL from

http://www.example.com/lookup.ph         


        
3条回答
  •  独厮守ぢ
    2020-12-10 07:18

    Simple .htaccess example:

    
    RewriteEngine On
    RewriteRule ^lookup/([a-z0-9\-]+)/item/?$ /lookup.php?id=$1
    
    

    This will match any alphanumeric (also will recognise dashes) string of any length as the 'id'. You can limit this to just numeric by changing the regex to ([0-9]+).

    
    RewriteEngine On
    RewriteRule ^lookup/([a-z0-9\-]+)/([a-z0-9\-]+)/?$ /lookup.php?id=$1&view=$2
    
    

    This one will match /lookup/123/some-text/ to /lookup.php?id=123&view=some-text

提交回复
热议问题