处理$ _ GET请求,用干净的网址 [英] Handle $_GET requests with Clean URLs
问题描述
我有一个明确的URL为基础的系统,以便类别将显示像这样
http://www.mysite.com/category/23/cat-name
在类别页面我有一些的排序和网页选项,如通过latests和更低的价格排序。另外,我有一个页面导航系统
现在的问题是,当请求发生在页面内的 $ _ GET []
不显示我需要的变量。然而,它示出在URL为
http://www.mysite.com/category/23/cat-name?page=3
在 $ _ GET
变量只能说明这是在我们的例子现在= 23
而忽视了类的ID页码是在URL中。
的.htaccess
内容
RewriteEngine叙述上
重写规则^类/([0-9] +)/ [AZ] [ - A-Z0-9] * $ cat.php ID = $ 1
您需要包含的 QSA 把你的统治结束。这追加任何现有的查询字符串,你构建的规则本身之一:
RewriteEngine叙述上
重写规则^类/([0-9] +)/ [AZ] [ - A-Z0-9] * $ cat.php ID = $ 1 [L,QSA]
于是重写URI应该结束了是: /cat.php?id=23&page=3
I am have a clear URL based system so the categories will be shown like this
http://www.mysite.com/category/23/cat-name
Inside the categories page I have some sorting and pages options such as sorting by latests and lower price. Also, I have a pages navigation system
The problem is when the request is happening inside the page the $_GET[]
doesn't show the variables I need. However it shows in the URL as
http://www.mysite.com/category/23/cat-name?page=3
The $_GET
variable only shows the id of the category which is in our case now = 23
and ignored the page number which is in the url.
.htaccess
content
RewriteEngine On
RewriteRule ^category/([0-9]+)/[a-z][-a-z0-9]*$ cat.php?id=$1
You need to include the QSA flag at the end of your rule. This appends any existing query string to the one that you're constructing in the rule itself:
RewriteEngine On
RewriteRule ^category/([0-9]+)/[a-z][-a-z0-9]*$ cat.php?id=$1 [L,QSA]
So the rewritten URI should end up being: /cat.php?id=23&page=3
这篇关于处理$ _ GET请求,用干净的网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!