重写规则帮助!第一次? [英] Rewrite Rule Help ! First Time?

查看:156
本文介绍了重写规则帮助!第一次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些帮助,It's我第一次使用重写规则中的链接。

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

我的网站是一个网上商店。

My website is a eshop.

的URL会是这样的:

www.mydomain.com/shop.php

www.mydomain.com/shop.php

这个文件,shop.php将获得高达3个参数throught的URL。

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

例如:

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

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

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

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

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

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:

案例1:www.mydomain.com/shop.html/1

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

案例2:www.mydomain.com/shop.html/1/FeaturesItems /

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

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

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

让我们想象一下,FeaturesItems的范畴,他的编号是数字1。

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

让我们想象一下,名优产品的子类别,他的编号是数字3。

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

你能不能帮我创造了重写规则?

Can you help me to create the rewrite rule?

另一个问题是,在shop.php我可以读取$ _GET ['类']的ID?

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

推荐答案

我想你想acomplish调用 /店/ 15 和internaly重定向这 shop.php?类别= 15 。然后做这样的事情:

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]

等等。

(未经测试)

可能得到怎样的mod_rewrite的作品更深入的样子。例如:

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

http://$c$c.tutsplus.com/tutorials/an-in-depth-guide-to-mod_rewrite-for-apache--net-6708 https://www.digitalocean.com/community/tutorials/how -to-建立,mod_rewrite的 http://www.workingwith.me.uk/articles/scripting/mod_rewrite

我也可以推荐外观极好 mod_rewrite的作弊张 。还要检查教程节还有。

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

这篇关于重写规则帮助!第一次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆