使用 RewriteRule 重定向表单获取请求

发布于 2024-08-23 16:37:47 字数 539 浏览 2 评论 0原文

好的,我有一个网站,用户可以将搜索查询放入使用 GET 发送数据的表单中。

发送后,网址如下所示:/recipes.php?query=taco&ingredients=chili
我想将其重写为如下所示: /recipes-taco-Ichili.html

因此,我将以下行添加到我的 .htaccess 文件中:

RewriteRule recipes\.php\?query=(.*)&ingredients=(.*)$ /recipes-$1-I$2.html [R]

我的印象是,这会将用户重定向到屏蔽后的页面,但 url 没有改变。

我打开了 RewriteEngine,一旦 url 出现在表单中
/recipes-something-Isomethingelse.html 它工作正常。

我过去使用 php 完成过此操作,但如果我能使用 .htaccess 完成此操作似乎会很好。

Okay, so I have a website where the user can put a search query into a form that uses GET to send the data.

When it gets sent, the url looks like: /recipes.php?query=taco&ingredients=chili
And I would like to rewrite it to look like: /recipes-taco-Ichili.html

So I added the following line to my .htaccess file:

RewriteRule recipes\.php\?query=(.*)&ingredients=(.*)$ /recipes-$1-I$2.html [R]

I was under the impression that this would redirect the user to the masked page, but the url doesn't change.

I have RewriteEngine onand once the url is in the form
/recipes-something-Isomethingelse.html it works fine.

I have done it in the past using php, but it seemed like it would be nice if I could do it with .htaccess.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南城追梦 2024-08-30 16:37:47

您无法在 RewriteRule 中获取查询字符串:

RewriteCond %{QUERY_STRING} ^query=([^&]*)&ingredients=(.*)$
RewriteRule ^recipes.php$ /recipes-%1-I%2.html [R]

You cannot get the query string in RewriteRule:

RewriteCond %{QUERY_STRING} ^query=([^&]*)&ingredients=(.*)$
RewriteRule ^recipes.php$ /recipes-%1-I%2.html [R]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文