i want to rewrite my variable
../detail.php?id=910&type=car
../book.php?id=910&type=car
to
../detail/car/910
../book/car/910
but i don't know how to code it, please give me the code and the explanation. Thanks
i want to rewrite my variable
../detail.php?id=910&type=car
../book.php?id=910&type=car
to
../detail/car/910
../book/car/910
but i don't know how to code it, please give me the code and the explanation. Thanks
Just go to .htaccess
file make sure your RewriteEngine on
then write following "RewriteRule" for your URLs:
RewriteRule ^detail/(.*)/(.*)$ detail.php?type=$1&id=$2 [NC,L]
RewriteRule ^book/(.*)/(.*)$ book.php?type=$1&id=$2 [NC,L]
If yet your rewrite rule not works then add following lines before your rewrite rule
Options +FollowSymLinks
RewriteEngine On
Explanation of above rule:
RewriteRule
- Tells Apache that this like refers to a single RewriteRule
.
^detail/(.*)/(.*)$ or ^book/(.*)/(.*)$
- The pattern. The server will check the URL of every request to the site to see if this pattern matches. If it does, then Apache will swap the URL of the request for the substitution section that follows.
detail.php?type=$1&id=$2 or book.php?type=$1&id=$2
- The substitution. If the pattern above matches the request, Apache uses this URL instead of the requested URL.
[NC,L]
- Flags, that tell Apache how to apply the rule. In this case, we're using two flags. NC
, tells Apache that this rule should be case-insensitive, and L
tells Apache not to process any more rules if this one is used.