开发者

modrewrite question

i'm having a geo database like the following

id contintent
------------
1  europe
2  usa 

id country
-----------
21 germany
22 france

id  city
-----------
50 paris
51 berlin

let's say i'm having this url: /show.php?contintentID=1&countryID=21&cityID=51

how can i translate it using modrewrite to a proper like: /europe/germany/berlin/index.html

i think it's beyond usual modrewrite .. any ide开发者_如何学Pythonas? please help - thanks!


why would it be beyond usual modrewrite? If you make sure there's a proper field in the database that has no special characters (I always call this field pre_field_seo, for news title this would be: new_title_seo) where I put the title without spaces, special characters etc. so SEO ready.

The demo data you provider is perfect, but make sure you don't have München for example, the right seo name would be munchen or muenchen in that case, whatever fits you best.

There's only one rewriterul needed:

RewriteRule /([a-zA-Z]+)/([a-zA-Z]+)/([a-zA-Z]+)/index.html show.php?continentName=$1&countryName=$2&cityName=$3 [L]

Ofcourse this also means that show.php must be converted in order to find the names in your database instead of the IDs. The IDs however can be added and used with the following setup:

/1-europe/21-germany/51-berlin/index.html

In that case you would need this rewriterule:

RewriteRule /([0-9]+)-([a-zA-Z]+)/([0-9]+)-([a-zA-Z]+)/([0-9]+)-([a-zA-Z]+)/index.html show.php?continentID=$1&countryID=$3&cityID=$5


You are correct. mod_rewrite cannot do this as it cannot access the database.

So instead you just need to write show.php so that it looks up the relative id numbers in the database and then constructs the new URL using the $continent/$country/$city/index.html and redirects to it using http_redirect.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜