Rewrite rules don't actually hide the query string, rewrite rules pretty much convert SEO friendly urls into the actual query string.
Example .htaccess:
RewriteEngine onThe above rewrite rule will allow you to do something like this:
RewriteRule ([a-zA-Z0-9_]+)\.html$ viewPage.php?ID=$1 [L]
url reads: yoursite.com/test.html
apache interprets as: yoursite.com/viewPage.php?ID=test
Therefore the following PHP code:
<?phpwill output test.
$id=$_GET['ID'];
echo $id;
?>
What if we want to pass more than one value, like "yoursite.com/viewPage.php?ID=test&category=coding" ?
We just have to convert /categories/coding/test.html into /viewPage.php?category=coding&ID=test
This will do the trick:
RewriteEngine On
RewriteRule ^categories/(\w+)/(\w+)\.html viewPage.php?category=$1&ID=$2 [L]
No comments:
Post a Comment