简体   繁体   English

mod_rewrite查询字符串

[英]mod_rewrite for query string

I have got 3 cases of 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

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? 您能描述一个适用于所有3种情况的mod_rewrite规则吗? Right now if a city or location is missing, the page returns 404. It only works if all the 3 parameters are present. 现在,如果缺少城市或位置,页面将返回404。仅在所有3个参数都存在的情况下,此页面才有效。 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. 它适用于您的所有3个URL。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM