通过 url 重写处理 url 中的空白值
我正在为我的购物车网站进行 url 重写,我想重写登录页面的 url。但是,当用户来自购物车页面时,URL 中附加的参数很少,因此我们可以根据这些参数再次将用户重定向到购物车。一种情况是该用户直接从登录超链接进入登录页面。所以在这种情况下附加值为空。
我编写了如下所示的 url 重写规则。
RewriteRule ^login/(.*)/(.*)/(.*)/(.*[^/])$ /index.php?file=login&ichangeid=$1&to=$2&from=$3&msg=$4
当所有四个参数都传递到 url 时,它工作正常,但是当 to 和 from 参数为 null 时,意味着用户直接来到登录页面,然后 url 的第一个参数传递给 $1 ,其余 //some_message 传递给 $2 和$3 和 $4 未存储。
那么我怎样才能实现这一目标呢?
I am doing url rewriting for my shopping cart website and these I want to rewrite the url of login page. But when user came from shopping cart page there are few parameters that are appended to the url, so that based on that we can redirect the user to shopping cart again. And one case if that user directly came to login page from login hyperlink. so in this case the additional values are null.
I wrote the url rewriting rules as given below.
RewriteRule ^login/(.*)/(.*)/(.*)/(.*[^/])$ /index.php?file=login&ichangeid=$1&to=$2&from=$3&msg=$4
It's works fine when all the four parameter are passed to the url but when to and from parameter are null, means user directly came to login page then the first parameter of the url is passed to $1 and rest //some_message are passed to $2 and $3 and $4 not getting stored.
So how can I achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不确定问题是什么。但是您可以使用以下命令将参数设为可选:
Not sure what the problem is. But you could make the parameters optional by using the following: