的.htaccess改写pretty的网址仍然可以使用GET变量可以使用、变量、网址、htaccess

2023-09-02 11:27:57 作者:只要99不要88

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

目前我试图用这样的:

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

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

这些大数据网站你都有get起来吗 非常实用

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

解决方案

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

您可以阅读更多关于 QSA (查询字符串追加)在这里: 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