在URL handliing空值与URL rewrittingURL、handliing、rewritting

2023-09-02 10:10:14 作者:望喜

我做URL重写我的购物车的网站,这些我想重写登录页面的URL。但是,当用户来自购物车页面有被附加到URL参数少,因此,基于我们可以再次将用户重定向到购物车中。一情况下,如果用户直接来到从登录超级链接登录页面。所以在这种情况下,附加的值为空。

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.

我写的UR​​L重写规则,如下面给出的。

I wrote the url rewriting rules as given below.

RewriteRule ^login/(.*)/(.*)/(.*)/(.*[^/])$ /index.php?file=login&ichangeid=$1&to=$2&from=$3&msg=$4

它正常工作时,所有四个参数传递给URL,但何时和参数都为空,意味着用户直接来到登录页面,然后URL的第一个参数传递给$ 1和休息// some_message传递至$ 2和$ 3和$ 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.

所以,我怎么能做到这一点。 任何帮助将AP preciated。

So how can I achieve this. Any help will be appreciated.

感谢

贾韦德Shamshedi

Jawed Shamshedi

推荐答案

不知道是什么问题。但是你可以使参数可选的使用下列内容:

Not sure what the problem is. But you could make the parameters optional by using the following:

RewriteRule ^login(?:/(.*))(?:/(.*))(?:/(.*))(?:/(.*[^/]))$ /index.php?file=login&ichangeid=$1&to=$2&from=$3&msg=$4