【问题标题】:Convert a query string to user friendly URL [duplicate]将查询字符串转换为用户友好的 URL [重复]
【发布时间】:2014-06-25 21:51:26
【问题描述】:

【问题讨论】:

  • 转发不会给你答案。这个话题已经被报道得令人作呕,而且你不会因为自己的一些谷歌搜索和研究而负担过重。
  • 谷歌搜索?他已经通过用url-rewriting标记他的“问题”给出了答案。

标签: php url-rewriting


【解决方案1】:

这是最简单的方法。
首先在.htaccess开启mod_rewrite
像这样:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . category_listing.php

接下来需要解析category_listing.php中的查询字符串
例如:

$query = explode('/', $_SERVER['REQUEST_URI']);
$city = $query[0]; // 'Bangalore'
$search = $query[1]; // 'Astrology'

使用数组索引,它可能是 1 和 2 而不是 0 和 1,具体取决于您的服务器设置。

仅此而已!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-27
    • 1970-01-01
    相关资源
    最近更新 更多