【问题标题】:Using htaccess to rewrite URL with GET variable to page title使用 htaccess 将带有 GET 变量的 URL 重写为页面标题
【发布时间】:2015-10-03 16:32:51
【问题描述】:

我正在尝试重写如下 URL:

http://example.com/shop/item.php?id=2

类似于:

http://example.com/shop/my-page-title-2.html

由于可能有多个项目具有相同的页面标题,我想将 ID 添加到 URL,因为每个 ID 都是唯一的,并且将确保我没有任何重复的 URL。

还应重写页面标题,以便 URL 的所有内容都为小写。

任何帮助将不胜感激!

【问题讨论】:

  • .htaccess rewrite GET variables 的可能重复项
  • @user2662639 虽然这个问题很可能以前被问过,但这不是一个很好的重复。
  • 我不明白你为什么要这样做,通常它会以相反的方式重写。
  • @TinyGiant 我想这样重写 URL 以用于 SEO 目的,在 URL 中包含关键字。
  • 我仍然不清楚你的意图。 mod_rewrite 更改跟随的 url,它不会更改浏览器可见的 url,因此这不会改变 SEO 看到的内容

标签: html .htaccess


【解决方案1】:

你可以遵循以下规则:

RewriteEngine On
RewriteCond %{THE_REQUEST} /shop/item.php\?id=([^&\s]+) [NC] 
RewriteRule ^ /my-page-title-%1\.html? [NC,R,L,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^my-page-title-([^.]+)\.html$ /shop/item.php?id=$1 [QSA,L,NC]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-09-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-02
    • 1970-01-01
    • 2016-05-08
    相关资源
    最近更新 更多