如何为查询字符串创建SEO url


How do I create a SEO url for query string

假设我的URL是http://domain.com/category.php?id=2,可以查看cars类别中的所有文章。

我的数据库结构category table

cat_id  cat_name
--------------------
1       books
2       cars

content table

con_id  con_title                con_cat
----------------------------------------
1       How to be a picker           1 
2       How to repair your car       2 
3       How to sell your car easily  2 

如何将我当前的URL更改为SEO友好型?所以应该是

http://domain.com/category/cars/

那么如何告诉查询/cars/等于content table中的2呢?

实际上,最好使用HTTP服务器的mod_rewrite功能。而不是说/汽车/你会说

   mysite.com/articles/How+to+repair+your+car/  

这将更加SEO友好。

您需要阅读mod_rewrite的工作原理和正确语法教程,但简而言之,您将编写一个规则,接受/articles/之后的内容,并将其(在服务器端)转换为类似的内容

   category.php?title=How+to+repair+your+car   

您将编写一些特殊的PHP代码来以这种方式查询类别。这样,你的代码是通用的,当你添加新的类别时,你不必更改任何其他内容,新的URL就会起作用。如果你试图为每个类别硬编码一个规则,那么你就是在做不必要的工作。