开发者

Mod_Rewrite using Category ID and optional Start Number, and Sort Data? How to do it?

开发者 https://www.devze.com 2023-03-28 09:17 出处:网络
I\'ve got a search page that I wanted to make mod_rewrite. So the query string is in general: index.php?CategoryName=Test&Start=10&Sort=1

I've got a search page that I wanted to make mod_rewrite.

So the query string is in general: index.php?CategoryName=Test&Start=10&Sort=1

  • CategoryName = TEXT [Required] - Used to find the category data & products.
  • Start = INTEG开发者_JAVA百科ER [Optional] - Used to find which product to start from.
  • Sort = INTEGER [Optional] - What sorting is done on the products, i.e. HIgh - low pricing...

Now, I want mod_rewrite to work with like 'category-test' or if its a certain page with sort data come out like 'category-test-5-1' etc...

Do I need to write a mod_rewrite for without any start,sort variables, with start, with sort etc or can I write just one piece of code to allow either the 2 'start' & 'sort' to not even be there.

Because when I write currently all the vars in and ones missing no results show, I get a 404.

My Current Code is:

RewriteRule ^category-([A-Za-z0-9_-]+)-([0-9])$ index.php?CategoryTitle=$1&Start=$2 [L]


You can write one rewrite and pass the part that you want to parse into your script as an additional parameter and parse that one within PHP then. this is how many sites are doing it.

Alternatively you can write multiple rewrites for each case as you already thought about.

0

精彩评论

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

关注公众号