Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I need some help, It′s my first time using the Rewrite Rule for a link.

My website is a eshop.

The url will be something like this:

www.mydomain.com/shop.php

This file, shop.php will receive up to 3 parameters throught the url.

Example:

Case 1: www.mydomain.com/shop.php?page=1

Case 2: www.mydomain.com/shop.php?page=1&category=1

Case 3: www.mydomain.com/shop.php?page=1&category=1&subcategory=3

What I need is that the Rewrite Rule returns me something like:

Case 1: www.mydomain.com/shop.html/1

Case 2: www.mydomain.com/shop.html/1/FeaturesItems/

Case 3: www.mydomain.com/shop.html/1/FeaturesItems/BrandName

Let's Imagine that FeaturesItems is the Category that his Id is the number 1.

Let's Imagine that BrandName is the SubCategory that his Id is the number 3.

Can you help me to create the rewrite rule?

The other question is, in shop.php I can read the $_GET['category'] with the Id?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
205 views
Welcome To Ask or Share your Answers For Others

1 Answer

I think you want to acomplish a call to /shop/15 and redirect this internaly to shop.php?category=15. Then do something like this:

RewriteRule ^shop.html/(d+)$ shop.php?category=$1 [L]
RewriteRule ^shop.html/(d+)/FeaturedItems/ shop.php?category=$1&featured=1 [L]

and so on.

(untested)

Maybe get a more indepth look of how mod_rewrite works. For example:

http://code.tutsplus.com/tutorials/an-in-depth-guide-to-mod_rewrite-for-apache--net-6708 https://www.digitalocean.com/community/tutorials/how-to-set-up-mod_rewrite http://www.workingwith.me.uk/articles/scripting/mod_rewrite

I could also recommend the excelent mod_rewrite-Cheat-Sheet. Also check the tutorial section there.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...