本文介绍了mod_rewrite的查询字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有3箱子的mod_rewrite的:

  http://www.domain.com/location/albania/tirana/tirana-airport
http://www.domain.com/location/albania/tirana
http://www.domain.com/location/albania
 

的实际URL所有这些情况将是:

<$p$p><$c$c>http://www.domain.com/page.php?country=albania&city=tirana&location=tirana-airport

你能描述mod_rewrite的规则,可以为三种情况下工作?现在如果一个城市或地点丢失,该页面返回404。只有当所有的3个参数是present。继承人的规则,我使用的是现在:

 重写规则^位置/([^/]+)/([^/]+)/([^/]+)(.*)$ page.php?国= $ 1安培;城市= $ 2及位置= $ 3
 

在此先感谢!

解决方案

替换您的规则与此:

 重写规则^位置/([^ /] +)/?([^ /] *)/?([^ /] *)/ $ /page.php?country = $ 1安培;城市2 = $&放大器;位置= $ 3 [L,QSA,NC]
 

它适用于所有3个网址的。

I have got 3 cases of mod_rewrite:

http://www.domain.com/location/albania/tirana/tirana-airport
http://www.domain.com/location/albania/tirana
http://www.domain.com/location/albania

The actual url for all these cases would be:

http://www.domain.com/page.php?country=albania&city=tirana&location=tirana-airport

Can you describe a mod_rewrite rule which can work for all 3 cases? Right now if a city or location is missing, the page returns 404. It only works if all the 3 parameters are present. Heres the rule I am using right now:

RewriteRule ^location/([^/]+)/([^/]+)/([^/]+)(.*)$ page.php?country=$1&city=$2&location=$3

Thanks in advance!

解决方案

Replace your rule with this:

RewriteRule ^location/([^/]+)/?([^/]*)/?([^/]*)/?$ /page.php?country=$1&city=$2&location=$3 [L,QSA,NC]

It works with all 3 of your URLs.

这篇关于mod_rewrite的查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-26 06:55