My file is category.php?id=
and here is my code:
<a href="category.php?id=<?php echo $row['id'];?>"><?php echo $row['name'];?></a>
I want to change url to site.com/category/title-here/id
. How can I rewrite it with .htaccess
?
Here is my .htaccess
for detail.php
page and it is working fine as site.com/detail.php?id=1
to site.com/title-here/1
:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.name.com [NC]
RewriteRule ^(.*)$ http://name.com/$1 [L,R=301]
AddDefaultCharset UTF-8
RewriteRule ^/(css|js|img)/(.*)?$ /$1/$2 [L,QSA,R=301]
RewriteRule ^([a-zA-Z0-9-/]+)/([a-zA-Z0-9-/]+)/?$ detail.php?title=$1&id=$2
RewriteRule ^([a-zA-Z0-9-/]+)/?$ detail.php?id=$1
Options -Indexes
2
Answers
As for detail page you can add the same rule with a
category
prefix:Try This
Now Your URL is Showing Like this
http://name.com/category/your-title-here?id=1