Home >Backend Development >PHP Tutorial >How can I use .htaccess to create pretty URLs from query parameters?
Creating Pretty URLs with .htaccess
Question: How can I transform a URL from http://localhost/index.php?user=1&action=update to http://localhost/user/1/update using .htaccess?
Answer:
To achieve this transformation, you can use the following .htaccess rules:
Options +FollowSymLinks RewriteEngine On RewriteRule ^user/([0-9]*)/([a-z]*)$ ./index.php?user=&action=
Explanation:
To Access Parameters in PHP:
To access the extracted parameters in your PHP code, use the following:
<code class="php"><?php echo "user id:" . $_GET['user']; echo "<br>action:" . $_GET['action']; ?></code>
Note:
The above is the detailed content of How can I use .htaccess to create pretty URLs from query parameters?. For more information, please follow other related articles on the PHP Chinese website!