Search code examples
php.htaccessurl-rewritingvar

rewrite rule htaccess php multiple vars


i need a simple rewrite rule with mulitple vars from

from:
index.php?id=steckbrief&art=steinkauz
to
/steckbrief/steinkauz/
or
/steckbrief/steinkauz.html

i found several examples, but perhaps another line of my rewrite rules blocks the rewrite? because i also want the single var and get it with:
RewriteRule ^(.*).html$ index.php?id=$1 [NC,L]

something like this :

RewriteRule ^steckbrief/?$ /index.php?id=steckbrief=$1&art=$2 [L,NC,QSA]

...

RewriteRule ^/([a-z]+)/([a-z]+)\$ index.php?id=$1&art=$2 [NC] works so far: RewriteRule ^steckbrief/([0-9A-Za-z-]+)$ index.php?id=steckbrief&art=$1 i am new to it
thanks for advice

example map: http://steinkauz.info/steckbrief/steinkauz.html


Solution

  • You can use explode to do that.
    This is the easiest way.

    Regex: RewriteRule ^([a-z]+)\/([a-z]+)$ index.php?id=$0 [NC]

    PHP: $art = explode("/", $_GET["id"])[1];