本文介绍了如何重写这些URL为国家,州,城市?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里的文章被来自世界各地提交,我记录下来的位置,如国家网站 - >状态 - >城市,对于像我正在生成URL:

I have a site where articles being submitted from worldwide and I record the location of them as Country -> State -> City, for that I am generating URLs like:

site/location/countryname/statename/cityname

我可以采取要求来照顾,并在查询字符串值,得到一个单一的PHP文件,现在的问题是怎么写的mod_rewrite所以它可以有URL像上面?

I have a single php file which can take care of coming request and gets values in query string, now the problem is how to write mod_rewrite so it can have URL like above?

PS:如果有人删除或Statename的这COUNTRYNAME不应该传递空值,意味着URL可以是:

PS: It should not pass empty values if someone deletes the statename or countryname, means URL can be:

site/location/countryname
site/location/countryname/statename
site/location/countryname/statename/cityname

但不能是:

site/location//statename/cityname
site/location/countryname//cityname

在上面的网址,如果COUNTRYNAME被删除,那么Statename的不应该被视为COUNTRYNAME。读文件名为 location.php

In above urls if countryname is deleted then statename shouldnt be treated as countryname. Reading file name is location.php

谢谢,

推荐答案

好吧我有一个办法做到这一点:

Ok I have got a way to do that:

RewriteRule ^bylocation/([-a-z_]+)(?:/([-a-z_]+)(?:/([-a-z_]+))?)?/?$ location.php?country=$1&state=$2&city=$3 [NC,L,QSA]

这单一规则可以照顾,而不是三个规则。

This single rule can take care, instead of three rules.

这篇关于如何重写这些URL为国家,州,城市?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 16:11