的.htaccess改写pretty的网址仍然可以使用GET变量 [英] .htaccess rewrite pretty urls that can still use get variables

查看:152
本文介绍了的.htaccess改写pretty的网址仍然可以使用GET变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想写一个.htaccess线,将重写PHP脚本,但仍允许在结束时添加任何额外的GET变量。这可能吗?

目前我试图用这样的:

 重写规则^项/([^ /] *)([^ /] *)$ /item.php?id=$1&$2 [L]
 

这样做的目的是为了能够做的事情一样 blah.com/item/foo ,而且 blah.com/item/foo?巴=什么

目前它似乎正确地传递的第一部分, ID ,而不是休息。

解决方案

 重写规则^项/([^ /] *)([^ /] *)$ /item.php? ID = $ 1安培; $ 2 [L,QSA]
 

您可以阅读更多关于 QSA (查询字符串追加)在这里: <一href="https://httpd.apache.org/docs/2.0/mod/mod_rewrite.html">https://httpd.apache.org/docs/2.0/mod/mod_rewrite.html

I'm trying to write an .htaccess line that will rewrite to a php script but still allow any extra get variables to be added on the end. Is this possible?

Currently I'm trying to use this:

RewriteRule ^item/([^/]*)([^/]*)$ /item.php?id=$1&$2 [L]

The aim is to be able to do things like blah.com/item/foo, but also blah.com/item/foo?bar=whatever.

Currently it seems to correctly pass the first part, id, but not the rest.

解决方案

RewriteRule ^item/([^/]*)([^/]*)$ /item.php?id=$1&$2 [L,QSA]

You can read more about QSA (query string append) here: https://httpd.apache.org/docs/2.0/mod/mod_rewrite.html

这篇关于的.htaccess改写pretty的网址仍然可以使用GET变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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