使用url重写处理url中的空白值 [英] handling blank values in url with url rewriting

查看:105
本文介绍了使用url重写处理url中的空白值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为购物车网站进行URL重写,而我想重写登录页面的URL.但是,当用户来自购物车页面时,URL后面将附加少量参数,因此,基于此参数,我们可以再次将用户重定向到购物车.还有一种情况是该用户从登录超链接直接进入登录页面.因此在这种情况下,其他值将为null.

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.

我写了下面的url重写规则.

I wrote the url rewriting rules as given below.

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不会存储.

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.

那我该如何实现呢?

推荐答案

不确定是什么问题.但是您可以使用以下命令将参数设置为可选:

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

这篇关于使用url重写处理url中的空白值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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