mod_rewrite的查询字符串字符串、mod_rewrite

由网友(久病成医)分享简介:我有3箱子的mod_rewrite的:http://www.domain.com/location/albania/tirana/tirana-airporthttp://www.domain.com/location/albania/tiranahttp://www.domain.com/location/alb...

我有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所有这些情况将是:

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

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

 重写规则^位置/([^/]+)/([^/]+)/([^/]+)(.*)$ page.php?国= $ 1安培;城市= $ 2及位置= $ 3
 
使用apache mod rewrite方法随机提供payloads

在此先感谢!

解决方案

替换您的规则与此:

 重写规则^位置/([^ /] +)/?([^ /] *)/?([^ /] *)/ $ /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.

阅读全文

相关推荐

最新文章