假设我的网址为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
如何将当前网址更改为SEO友好?所以它应该是
http://domain.com/category/cars/
那么如何告诉/cars/
中的2
等于content table
的查询?
答案 0 :(得分:3)
实际上更好的方法是使用HTTP服务器的mod_rewrite功能。而不是说/ cars /你会说
mysite.com/articles/How+to+repair+your+car/
这将更加SEO友好。
你需要read a tutorial how mod_rewrite works和正确的语法,但简而言之,你将编写一个规则,接受/ articles /后的任何内容(并在服务器端)转换为
category.php?title=How+to+repair+your+car
并且您将编写一些特殊的PHP代码来以这种方式查询类别。这样您的代码就是通用的,当您添加新类别时,您不必更改任何其他内容,新的URL将起作用。如果您尝试为每个类别硬编码规则,则会创建不需要的工作。