English 中文(简体)
modrewrite问题
原标题:modrewrite question

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

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 ideas? please help - thanks!

最佳回答

为什么它会超出通常的modrewrite?如果你确保数据库中有一个没有特殊字符的适当字段(我总是把这个字段称为pre_field_so,对于新闻标题,这将是:new_title_seo),我把标题放在那里,没有空格、特殊字符等,所以seo准备好了。

你提供的演示数据是完美的,但请确保你没有München,例如,在这种情况下,正确的seo名称应该是machen或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号,然后使用$continent/$country/$city/index.html构建新的URL,并使用http_redirect重定向到它。





相关问题
Using SimplePie with CodeIgniter and XAMPP

I am using CodeIgniter 1.7.2 with XAMPP 1.7.2 on a Windows computer. I am trying to make use of SimplePie. I followed all the instructions I could find: a copy of simplepie.inc is in my applications/...

Multiple Sites with common files

I have developed over 50 sites that all use the exact same files other than CSS and IMAGES, I currently duplicate the files each time I create a new site and upload different css and images. What ...

http server validation

I finish a litle http server, writing from scratch. I would like to be sure that my imlementation is conforme to the HTTP specifications. W3C give us tools for HTML/XML conformance, but i see nothing ...

热门标签