【问题标题】:by using .htaccess file change the url parameter value通过使用 .htaccess 文件更改 url 参数值
【发布时间】:2014-02-26 01:44:25
【问题描述】:

我的 htacess 代码是:

Options +FollowSymLinks

RewriteEngine on

RewriteBase /demo/kingstate/

RewriteCond %{THE_REQUEST} /detail\.php\?id=([^\s&]+) [NC]

RewriteRule ^ id/%1? [R=302,L]

RewriteRule ^id/([0-9]+)/?$ detail.php?id=$1 [L,QSA,NC].

我的网址从 http://tinmandevserver.com/demo/kingstate/detail.php?id=1 更改为

http://tinmandevserver.com/demo/kingstate/id/1 使用 htaccess 文件,但我想要一个 url

点赞http://tinmandevserver.com/demo/kingstate/propperty-house-victoria

这是我第一次编写 htaccess 代码。

【问题讨论】:

  • “proppery-house-victoria”从何而来?
  • property 是静态值,因为 house 是一种属性类型,它可能是 house,apartment nd 等等,维多利亚是地方......我如何在我的 url 中获得这个值

标签: php .htaccess


【解决方案1】:

您不能轻易地使用 mod_rewrite 执行从 http://...?id=1(或类似的)到 http://.../some-long-name 的查找,除非您为每个 number-to-name 值对添加一条规则(RewriteRule 行)。

您可能想要做的是使用 PHP(也可能是 SQL)来查找给定数字的名称,然后进行重定向。例如:

<?php
    $long_names = array('some-long-name','another-long-name');
    if (!empty($_GET['id'])) {
        header("Location: /demo/kingstate/".$long_names[$_GET['id']]);
        exit;
    }

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2012-12-10
  • 2014-03-15
  • 2011-12-25
  • 2011-08-13
  • 2019-11-22
  • 2014-04-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多