【问题标题】:How I use .htacces Rewrite Engine我如何使用 .htacces 重写引擎
【发布时间】:2015-03-04 16:30:24
【问题描述】:

我想通过使用页面标题而不是 php get 方法来改进我的网站。

如果我要将/index.php?id=1 转换为/page,我需要在.htacces 中写什么

【问题讨论】:

  • 将需要的不仅仅是 mod_rewrite,除非您打算为每个页面 id 编写规则。 index.php 需要一种将每个 fake URL 映射到实际页面 id 的方法,通常使用一种 db 查找表:有关重写部分,请参阅 stackoverflow.com/questions/18406156/…
  • 这个语法更好,我把代码格式化了。应该澄清“使用页面标题而不是php”

标签: php apache .htaccess rewrite server


【解决方案1】:
RewriteRule ^page$ /index.php?id=1 [L]

如果你想重写每个 index.php?id=ID_HERE 使用这个:

RewriteRule ^page/([^/]*)$ /index.php?id=$1 [L]

【讨论】:

  • 虽然从技术上讲,这可以工作,每个页面都需要在 .htaccess 文件中进行映射; page2 => index.php?id=2 ... page3 => index.php?id=3 等等。这有点……不雅。
猜你喜欢
  • 1970-01-01
  • 2015-03-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-07
  • 1970-01-01
  • 2015-07-09
  • 2012-11-30
相关资源
最近更新 更多