If you want to turn
http://www.yourwebsite.com/index.php?user=1&action=update
into
http://www.yourwebsite.com/user/1/update
You could use
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^user/([0-9]*)/([a-z]*)$ ./index.php?user=$1&action=$2
To see the parameters in PHP:
<?php
echo "user id:" . $_GET['user'];
echo "<br>action:" . $_GET['action'];
?>
- The parenthesis in the .htaccess are groups that you can call later.
with $1, $2, etc.
- The first group I added ([0-9]*) means that it will
get any numbers (1, 34, etc.).
- The second group means any characters
(a, abc, update, etc.).
This is, in my opinion, a little bit more clean and secure than (.*) which basically mean almost anything is accepted.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…