使用 RewriteRule 重定向表单获取请求
好的,我有一个网站,用户可以将搜索查询放入使用 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 on
and 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您无法在
RewriteRule
中获取查询字符串:You cannot get the query string in
RewriteRule
: