modrewrite问题
我有一个如下所示的地理数据库,
id contintent
------------
1 europe
2 usa
id country
-----------
21 germany
22 france
id city
-----------
50 paris
51 berlin
假设我有这个网址: /show.php?contintentID=1&countryID=21&cityID=51
我如何使用 modrewrite 将其翻译为正确的形式,例如: /europe/germany/berlin/index.html
我认为这超出了通常的 modrewrite .. 有什么想法吗?请帮忙 - 谢谢!
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 ideas? please help - thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么它会超出通常的 modrewrite 范围?如果您确保数据库中有一个没有特殊字符的正确字段(我总是将此字段称为 pre_field_seo,对于新闻标题,这将是:new_title_seo),我将标题中没有空格、特殊字符等放在其中,以便 SEO 做好准备。
您提供的演示数据是完美的,但请确保您没有 München,例如,正确的 seo 名称将是 munchen 或 muenchen 在这种情况下,无论什么最适合您。
只需要一个重写器:
当然,这也意味着必须转换 show.php 才能在数据库中查找名称而不是 ID。但是,可以通过以下设置添加和使用 ID:
在这种情况下,您将需要此重写规则:
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:
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:
In that case you would need this rewriterule:
你是对的。 mod_rewrite 无法执行此操作,因为它无法访问数据库。
因此,您只需要编写 show.php,以便它在数据库中查找相对 ID 号,然后使用
$Continue/$country/$city/index.html
构建新的 URL 并使用 http_redirect 重定向到它。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.