带参数的 url 的 RewriteCond [英] RewriteCond for url with parameters

查看:32
本文介绍了带参数的 url 的 RewriteCond的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在重写 url 时遇到问题.我想要这个:

I've got a problem to rewrite an url. I want this :

http://www.foo.com/test.php?u=s1&id=12345&img=12

http://app.foo.com/12345-s1-12.test

第一个参数u是一个字符串,参数id和img是整数.

First parameter u is a string, parameters id and img are integers.

我已经开始了类似的事情:

I've started with something like that :

RewriteCond %{REQUEST_URI} ^/test.php?u=(.*)&id=(.*)&img=(.*)/ [NC]
RewriteRule (.*) http://app.foo.com/%2-%1-%3.test [QSA,R=301,L]

谢谢:)

仍然不起作用,但我已经接近了!

Still doesn't work but i'm close!

RewriteCond %{REQUEST_URI} ^/test.php [NC]
RewriteCond %{QUERY_STRING} ^u=(.*)&id=(.*)&img=(.*)
RewriteRule (.*) http://app.foo.com/%2-%1-%3.test [QSA,R=301,L]

现在它给了我那个链接:

Now it give me that link :

http://app.foo.com/12345-s1-12.test?u=s1&id=12345&img=12

代替:

http://app.foo.com/12345-s1-12.test

:(

推荐答案

已解决!

RewriteCond %{REQUEST_URI} ^/test.php [NC]
RewriteCond %{QUERY_STRING} ^u=(.*)&id=(.*)&img=(.*)
RewriteRule (.*) http://app.foo.com/%2-%1-%3.test? [R=301,L]

在 RewriteRule 的末尾放置 ? 会删除之前的查询字符串信息.

Placing a ? on the end of the RewriteRule removes previous query string information.

这篇关于带参数的 url 的 RewriteCond的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆