开发者

friendly url without any parameters with htaccess

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.


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).


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.


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


Use htaccess with a rewrite rule:

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

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜