php - Wrong $_GET params using MOD rewrite -
i trying make url more friendly, domain/link/link.php?id=123 domain/link/123
i have written following rule:
rewriteengine on rewriterule ^([^/]*)$ link.php?id=$1 [l]
it on .htaccess in /link folder.
in link.php file have:
echo $_get['id'];
but result "link.php" without quotes, instead of number or string.
what doing wrong?
you have specified last rule using l
flag, rewritten url requested, rewritten again.
there 2 possible solutions:
- check if file exists , rewrite if not;
- restrict rewriting rules looks numbers.
an example of first option:
rewriteengine on rewritecond %{request_filename} !-f rewritecond %{request_filename} !-d rewriterule ^([^/]+)$ link.php?id=$1 [l]
(note have changed *
0 or more +
1 or more)
an example of second option:
rewriteengine on rewriterule ^(\d+)$ link.php?id=$1 [l] ^^^ 1 or more digits
Comments
Post a Comment