php - friendly url without any parameters with htaccess

901

I want to short my url, mainly to SEO, so I decided to change my url's on my website.

Now the urls looking like

http://www.domain.com/cat.php?id=5 while the category's name is "example cat"

I want that the url will look like

http://www.domain.com/example-cat/

How can I do it? Thank you very much.

118

Answer

Solution:

The proper solution is to include both the ID and the name. Otherwise name changes will break all links stored by search engines, users, etc.

http://www.example.com/5/example-cat/ or http://www.example.com/5-example-cat/ or whatever you like (with the ID still being easily extractable with a regex).

131

Answer

Solution:

You wouldn't. You'd set it up to rewrite from:

http://www.domain.com/5/

to

http://www.domain.com/cat.php?id=5

If you wanted to use the category names, you'd need to change the php on the back end to accept them.

126

Answer

Solution:

You could always push 'everything' through your index.php file and use it to bootstrap the entire site.. have a look at this

548

Answer

Solution:

Use htaccess with a rewrite rule:

RewriteEngine on
RewriteRule ^([^/\.]+)/?$  /cat.php?id=$1 [NC,L]

So..example.com/category would be re-written toexample.com/browse.php?cat=category.

People are also looking for solutions to the problem: php - Update MySQL database from XML file

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.