【问题标题】:.htaccess Rewrite url to query string.htaccess 将 url 重写为查询字符串
【发布时间】:2016-06-23 00:46:23
【问题描述】:

当我将图片上传到我的网站时,它们的链接如下所示:

https://mywebsite.com/photo/9/ 等等..只有数字变化

我想把它改写成查询字符串,像这样:

https://mywebsite.com/p?id=9 等等。

这是我尝试做的,但它不起作用:

RewriteRule ^/photo/([0-9]+) /p?id=$1

【问题讨论】:

  • 当你说你想重写它?你想在浏览器栏中显示什么?让我们开始吧。
  • 我想完全重写网址,所以它会通过查询字符串打开并显示在浏览器栏中而不是旧的

标签: .htaccess query-string


【解决方案1】:

试试这个:

RewriteEngine On
RewriteRule ^photo/([^/]*)$ /p?id=$1 [L]

【讨论】:

    【解决方案2】:

    从 RewriteRule 的模式中删除前导斜杠,尝试:

    RewriteRule ^photo/([0-9]+)/?$ /p?id=$1 [L]
    

    【讨论】:

      猜你喜欢
      • 2021-12-10
      • 1970-01-01
      • 2012-11-15
      • 1970-01-01
      • 2023-03-04
      • 2012-06-16
      • 2012-09-19
      • 2012-10-11
      • 1970-01-01
      相关资源
      最近更新 更多