php - 如何使用自定义变量更改 url 变量

标签 php url mod-rewrite seo

<分区>

Possible Duplicate:
How to: URL re-writing in PHP?

我的意图是用另一个变量(自定义文本)更改通过 URL 传递的变量 (id)。 为了更清楚,我想更改:

来自

www.mysite.com/page.php?id=14

www.mysite.com/page.php?id=the_best_product_for_them

甚至更好

www.mysite.com/product/the_best_product_for_them

我的数据库中已经有一个表将 id='14' 与文本 'the_best_product_for_them' (id, product_name) 相关联

我想这就是 wordpress 对永久链接所做的事情。我也知道如何使用 .htaccess 文件手动执行此操作,但我想动态执行。我需要的是一个从哪里开始的方向,以及实现这个目标需要什么。

服务器是Apache,代码是PHP。

非常感谢, 朱利奥

最佳答案

我想您会在这里找到解决方案:Url Mod-Rewrite Get new Page with ID

# catch URL and  rewrite to index.php
RewriteRule ^product/([A-Za-z0-9-]+)/?$ index.php?id=$1 [NC,L]
  • 确保您的 Apache 服务器上有 mod_rewrite

关于php - 如何使用自定义变量更改 url 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14609450/

相关文章:

php - 重定向 301/重写难题

PHP 计算每天保存的文档总数

apache - 使用通配符通过 .htaccess 重定向

php - 有人可以帮助找出这个 PHP 文件中语句的问题吗?

ios - Facebook iOS 应用上的 URL 重定向不正确

javascript - 如何使用javascript获取url中的特定字符并将其存储到id?

json - 清除缓存的 URL

apache - 无法在 Apache htaccess 中重写和重定向 API URI

php - PHP 中的 UTF-8 和 IsAlpha()

php - 试图在 html 表中显示 SQL 数据