【问题标题】:Change URL to shorter [duplicate]将 URL 更改为更短 [重复]
【发布时间】:2014-12-18 00:53:43
【问题描述】:

我有一个网址

http://example.com/test/search.php?id=SearchWord

我想把它改成

http://example.com/test/SearchWord

现在我用 .htaccess 尝试了一些东西,但我无法让它工作,因为我需要 $_GET['id']

我有一个检查 $_GET['id'] 的 if 函数。

如何使用新的短网址以及如何缩短网址?

【问题讨论】:

  • 您对此进行过研究吗?看起来你没有。
  • 人们如何访问此页面?它是搜索表单的目标吗?

标签: php apache .htaccess


【解决方案1】:

试试这个...

RewriteEngine On
RewriteRule ^([^\.]+)$ search.php?id=$1 

【讨论】:

    【解决方案2】:

    您可以在 apache 中使用 mod_rewrite 来做到这一点。

    http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritebase

    这将让您为请求的 URL 设置正则表达式并将其转发到不同的 URL!

    【讨论】:

      【解决方案3】:

      在您的.htaccess 中,试试这个:

      RewriteEngine On
      RewriteRule ^test/(.*)$ /test/search.php?id=$1 [L]
      

      【讨论】:

      • 这给了我找不到!
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-14
      • 2012-11-11
      • 1970-01-01
      • 2011-07-30
      • 1970-01-01
      相关资源
      最近更新 更多