I'm trying to rewrite the following URL
www.domain.com/category.php?id=13
to:
www.domain.com/category/cat-name
I've followed some .htaccess tutorials but I couldn't. How can I make it work?
I'm trying to rewrite the following URL
www.domain.com/category.php?id=13
to:
www.domain.com/category/cat-name
I've followed some .htaccess tutorials but I couldn't. How can I make it work?
You cannot rewrite a number to a name, unless you have some way of translating that number to a name. This means that on the http deamon level (Apache/.htaccess) you don't have enough information to redirect it. For redirects in php, see this.
Since you ask about rewrites in php, I'll answer that too. There is no such thing as rewriting in a php file. An internal rewrite maps one url (e.g.
www.domain.com/category/cat-name
) and lets the server execute a different url (e.g.www.domain.com/category.php?id=13
). This happens on the http deamon level, in your case Apache.First make a .htaccess in your www-root:
In category.php:
This will redirect requests to category/name if you request category.php?id=number and get the name from the url if you request category/name