重写规则 - 两个参数,但最后一个参数是可选 [英] RewriteRule - two parameters but last parameter is optional

查看:129
本文介绍了重写规则 - 两个参数,但最后一个参数是可选的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不能重写包括两个参数,但最后一个参数是可选的,因此,例如:

  

http://www.mywebsite.com/friends/jamie - (正斜杠应选配太) 。这应该是相同的,因为这

  http://www.mywebsite.com/friends.php?name=jamie
 

在包括第二个参数

  

http://www.mywebsite.com/friends/jamie/30 - 应该是相同的这样的:

  http://www.mywebsite.com/friends.php?name=jamie&page=30
 

该规则不起作用:

 重写规则^朋友/(.*)/(.*)$ friends.php 1名= $&放大器;页= $ 2
 

由于我得到这样的:所请求的网址/朋友/在此服务器上找到杰米,但作品,如果我有第二个参数页号,所以基本上。第二个参数应该是可选的。

解决方案

尝试使用这个规则来代替:

 重写规则^朋友/([^/]*)/?(.*)$ friends.php 1名= $&放大器;页= $ 2
 

希望帮助

I cannot rewrite to include two parameters but the last parameter is optional, so for example:

http://www.mywebsite.com/friends/jamie - (the forward slash should be optional too). Which should be the same as this:

http://www.mywebsite.com/friends.php?name=jamie

When including a second parameter

http://www.mywebsite.com/friends/jamie/30 - Should be the same as this:

http://www.mywebsite.com/friends.php?name=jamie&page=30

This rule does not work:

RewriteRule ^friends/(.*)/(.*)$ friends.php?name=$1&page=$2

Because I get this: The requested URL /friends/jamie was not found on this server. but works if I include a page number for the second parameter, so basically the second parameter should be optional.

解决方案

Try using this rule instead:

RewriteRule ^friends/([^/]*)/?(.*)$ friends.php?name=$1&page=$2

Hope that helps

这篇关于重写规则 - 两个参数,但最后一个参数是可选的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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