Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
207 views
in Technique[技术] by (71.8m points)

php - Rewrite Rule Help ! First Time?

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

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

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...