Apache 改写问题

Apache 改写问题,apache,mod-rewrite,Apache,Mod Rewrite,我有一个地理数据库,如下所示 id contintent ------------ 1 europe 2 usa id country ----------- 21 germany 22 france id city ----------- 50 paris 51 berlin 假设我有一个url: /show.php?contintentID=1&countryID=21&cityID=51 如何使用modrewrite将其转换为适当的格式,如: /欧洲/德国/柏林/index.

我有一个地理数据库,如下所示

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

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

id  city
-----------
50 paris
51 berlin
假设我有一个url: /show.php?contintentID=1&countryID=21&cityID=51

如何使用modrewrite将其转换为适当的格式,如: /欧洲/德国/柏林/index.html

我认为这超出了通常的改写。。
有什么想法吗?请帮忙-谢谢

为什么会超出通常的修改?如果您确保数据库中有一个没有特殊字符的适当字段(我总是将此字段称为pre_field_seo,对于新闻标题,这将是:new_title_seo),我将标题放在没有空格、特殊字符等的位置,以便为seo做好准备

您提供的演示数据是完美的,但是请确保您没有munchen。例如,在这种情况下,正确的seo名称应该是munchen或muenchen,任何最适合您的名称

只需要一个重写规则:

RewriteRule /([a-zA-Z]+)/([a-zA-Z]+)/([a-zA-Z]+)/index.html show.php?continentName=$1&countryName=$2&cityName=$3 [L]
当然,这也意味着必须转换show.php才能在数据库中找到名称,而不是ID。但是,可以添加ID并与以下设置一起使用:

/1-europe/21-germany/51-berlin/index.html
在这种情况下,您需要以下规则:

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

你说得对。mod_rewrite无法执行此操作,因为它无法访问数据库


因此,您只需编写show.php,以便它在数据库中查找相对id号,然后使用
$contraction/$country/$city/index.html
构建新URL,并使用http_redirect重定向到它。

这没有意义,因为他已经拥有show.php,mod_rewrite完全能够做到这一点。另外,你的评论缺乏信息,没有任何关于mod_rewrite的知识(你告诉他mod_rewrite不能这么做),你有点让这个家伙蒙在鼓里。对不起,我将要给出-1。对不起@PENDO,我一定是误解了这个问题。我以为@fuxi想查询数据库,将ID号的查询字符串映射到相应名称的路径名。呵呵,不用担心!这些事情发生了!我删除了-1!(抱歉,除非您更改答案,否则无法删除,如果您愿意并在此处回复,我将删除-1)