url重写帮助

发布于 2024-09-01 11:48:59 字数 383 浏览 1 评论 0原文

我正在使用 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 技术交流群。

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

发布评论

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

评论(1

踏月而来 2024-09-08 11:48:59

如果您的意思是产品变量是根据 URL 的第一部分确定的,则可以这样做:

RewriteRule ^(.*)/(.*)$ /mobile_rating.php?alias=$2&product=$1 [L,B]

但是,我会将字符匹配从 .* 更改为不太通用的内容。上面的代码会将 /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:

RewriteRule ^(.*)/(.*)$ /mobile_rating.php?alias=$2&product=$1 [L,B]

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文