如何重写 get 方法传递值的 url 并将它们传递给另一个页面


How to rewrite a url in which values have been passed by get method and pass them to another page?

我正在使用Xampp,几乎做了所有事情。我有如下htaccess文件:

RewriteEngine On
RewriteRule ^q? query.php [NC]

此外,我已经打开了mod_rewrite模块,并将Allow None更改为http.conf Apache文件中的Allow All

我希望我的网址是localhost/abc/query.php?q=something&c=something而不是localhost/q?q=something&c=something

PS:它不是错别字,('q')页面实际上没有扩展名。

此规则应该在DOCUMENT_ROOT/.htaccess文件中对您有用:

RewriteEngine On
RewriteRule ^q/?$ /abc/query.php [L,NC]

基本上,您使用的是 q/index.php这就是为什么扩展被隐藏的原因,因为 index.php 被隐藏了。您要做的是:

<form action="abc/query.php" name="query" method="GET">
<input type="text" name="q" />
<input type="text" name="c" />
<input type="submit" />
</form>

然后它应该显示为 /abc/query.php?q=randomtext&c=randomtext .