【问题标题】:htaccess change url strings to simple slughtaccess 将 url 字符串更改为简单的 slug
【发布时间】:2018-10-11 09:32:37
【问题描述】:

这是我当前的网址

https://www.example.com/content.php?q=1&s=title-sample-slug

我需要使用这种类型的url来改变上面的url

https://www.example.com/title-sample-slug

我如何使用 htaccess 文件来做到这一点。需要在浏览器的 url 中隐藏 content.php?q=1&s=。

【问题讨论】:

标签: .htaccess url url-rewriting


【解决方案1】:
RewriteCond %{QUERY_STRING} q=1&s=(.+) 
RewriteRule content.php %1 [L]

【讨论】:

  • 不工作 :( 我需要重写 url 这就是 example.com/content.php?q=1&s=title-sample-slug 到 example.com/title-sample-slug :(
  • 仍然得到 :( 无论如何谢谢你试图帮助我 :)
  • with RewriteRule content.php %1 [L,QSD] 它对我有用:新的 url 是 :80/title-sample-slug
  • 实际上它正在工作,但是当我们更改 (q= value) 时出现错误,因此参数需要是动态的,我该怎么做
【解决方案2】:

这是我问题的正确答案

RewriteCond %{QUERY_STRING} q=([0-9a-zA-Z_-]+)&s=([0-9a-zA-Z_-]+) 
RewriteRule content.php %2 [L,QSD]

【讨论】:

    猜你喜欢
    • 2021-09-17
    • 2014-08-07
    • 1970-01-01
    • 2014-10-03
    • 1970-01-01
    • 2013-09-04
    • 2021-03-19
    • 2015-11-12
    • 2011-02-19
    相关资源
    最近更新 更多