【问题标题】:RewriteRule with dynamic two parameters and one maybe missing具有动态两个参数的 RewriteRule 可能缺少一个
【发布时间】:2017-10-21 18:11:15
【问题描述】:

我有带有两个参数的 Rewriterule,它应该可以正常工作。 但有时也有可能第二个参数不存在或为空。

我的代码:

RewriteRule ^(\d+)/?$ ./index.php?firma=$1 

RewriteRule ^(\d+)-(.+)/?$ ./index.php?firma=$1&nimi=$2

第一个 $1 是数字值 第二个是字母。

我的问题示例。

我有一个网址:

https://www.someserver.com/1255554-SOME-LETTERS-AS

这会很好用!

https://www.someserver.com/1255554

这也可以正常工作并打开相同的页面。 但是因为我有超过 250 000 页,所以有些页面的 2 美元部分是空白的。 那么生成的网址是:

https://www.someserver.com/1255554-

现在这不是显示,它会说 404 我该如何解决?

【问题讨论】:

    标签: .htaccess mod-rewrite


    【解决方案1】:

    您可以在第一条规则中将尾随连字符设为可选:

    RewriteRule ^(\d+)-?/?$ ./index.php?firma=$1 [L,QSA]
    
    RewriteRule ^(\d+)-(.+)/?$ ./index.php?firma=$1&nimi=$2 [L,QSA]
    

    建议在目标 URI 中重写查询字符串时使用QSA 标志(查询字符串追加)。

    【讨论】:

      猜你喜欢
      • 2015-01-06
      • 2023-04-08
      • 2020-02-24
      • 2017-10-16
      • 2021-02-24
      • 2017-01-06
      • 1970-01-01
      • 2021-08-05
      • 1970-01-01
      相关资源
      最近更新 更多