url重写帮助
我正在使用 url 重写,这
RewriteRule ^mobiles/(.*)$ /mobile_rating.php?alias=$1 [L,B]
对我来说效果很好,就像
/mobiles/nokia70 /mobile_rating.php?alias=nokia70
我需要一个小的更改,就像
/mobiles/nokia70 /mobile_rating.php?alias=nokia70&product=mobiles
我的意思是说,url 中的手机必须更改为 Product=mobiles ..我该怎么做..任何提示
i am using url rewriting like
RewriteRule ^mobiles/(.*)$ /mobile_rating.php?alias=$1 [L,B]
which works well for me like
/mobiles/nokia70 /mobile_rating.php?alias=nokia70
i need a small change like
/mobiles/nokia70 /mobile_rating.php?alias=nokia70&product=mobiles
i mean to say like the mobiles in url must be changed to product=mobiles ..how do i do it..any tips
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您的意思是产品变量是根据 URL 的第一部分确定的,则可以这样做:
但是,我会将字符匹配从
.*
更改为不太通用的内容。上面的代码会将/mobiles/nokia70/abc
重写为/mobile_ rating.php?alias=abc&product=mobiles/nokia70
。[^/]+
将匹配不包含正斜杠的字符串,或者如果您始终使用严格的字母/数字集,请尝试[a-z0-9 -]+
将匹配任何小写字母、数字或连字符。If you mean that the product variable is determined from the first part of the URL, this will do it:
However, I would change the character match from
.*
to something less generic. The above will rewrite/mobiles/nokia70/abc
to/mobile_rating.php?alias=abc&product=mobiles/nokia70
.[^/]+
will match a string that doesn't contain the forward slash, or if you're always using a strict set of letters/numbers, try[a-z0-9-]+
which will match any lowercase letter, digit or the hyphen.