我想使用正则表达式提取一个国家的 ISO 代码(两个字母)。
例如,对于国家 Ireland
,ISO 代码是 ie
。ISO 代码可以在斜杠 /
或者最后一个点号 .
之后找到。
这是我的 RewriteRule
:
RewriteRule ^gallery/country(?:/[^/]*([a-zA-Z-9]{2}))?/?$ gallery/gallery.php?country=$1 [L,QSA]
以下是一些有效的网址... 如果可用,我想选取ISO代码:
gallery/country
gallery/country/
gallery/country/
ie
gallery/country/ie
/gallery/country/ireland
gallery/country/ireland/
gallery/country/ireland-love.
ie
gallery/country/ireland-love.ie
/gallery/country/ireland.69-love.
ie
/我尝试调整我几乎用于所有SEO网址的模板公式,但是我在这一个上遇到了困难。以下是目前为止我所做的。
^gallery/country(?:/[^/]*([a-zA-Z-9]{2}))?/?$