如何做才能让你的.htaccess通过所有GET参数不知道他们被命名为?让你、命名为、如何做、才能

2023-09-02 00:41:52 作者:青莳

我工作的一个CMS,涉及到自定义用户的网页。我有设置了三个级别的层级,和它的作品pretty的好。它有一个的.htaccess,使网址友好,太:

I am working on a CMS that involves custom user pages. I have a hierarchy with three levels set up, and it works pretty well. It's got a .htaccess that makes the URLs friendlier, too:

RewriteRule ^([A-Za-z0-9]+).html /content.php?page=$1 [L]
RewriteRule ^([A-Za-z0-9]+)/([A-Za-z0-9]+).html /content.php?page=$2 [L]
RewriteRule ^([A-Za-z0-9]+)/([A-Za-z0-9]+)/([A-Za-z0-9]+).html /content.php?page=$3 [L]

这code的作品就好。

That code works just fine.

这是我已经是添加自定义的PHP页面的情况下,我需要添加一些更强大的另外一个特点(如使,获取电子邮件地址,数据库中的联络方式)。

Another feature that I have is adding custom php page, in case I need to add something more powerful (like make a contact form that gets email addresses from a database).

所以我的问题是我怎么能修改(或添加到)的.htaccess使所有传递给PHP页面的GET参数。例如,使用的联系人页面例如,如果用户进入http://www.mysite.com/contact.html?name=someuser,我想要的.htaccess重写它作为content.php页=接触和放大器;名称= SomeUser的,但没有明确告诉它来寻找'名称'作为参数名。我也想用尽可能多的参数可以正常工作。

So my question is how could I modify (or add to) the .htaccess to make all of the GET parameters passed to the PHP page. For example, to use the contact page example, if the user goes to http://www.mysite.com/contact.html?name=someuser, I want the .htaccess to rewrite it as content.php?page=contact&name=someuser, but without specifically telling it to look for 'name' as the parameter name. I would also like it to work with as many parameters as possible.

我知道这是一个很大的(希望不是混乱)的要求,但是这可能吗?或者说,它至少部分?谢谢!

I know this is a big (and hopefully not confusing) request, but is it possible? Or at least parts of it? Thanks!

推荐答案

QSA添加到您的参数。所以对于你的第一个规则,它会成为

add QSA to your parameters. so for your first rule it would become

RewriteRule ^([A-Za-z0-9]+).html /content.php?page=$1 [L, QSA]