【问题标题】:htaccess rewrite slashes to dashes in parameter urlhtaccess 在参数 url 中将斜杠重写为破折号
【发布时间】:2015-06-04 09:30:58
【问题描述】:

我有以下重写设置,它适用于我 90% 的参数 url 重写,但我有一些参数名称包含斜杠的实例。

出于显而易见的原因,我需要将斜杠“/”替换为破折号“-”。我该怎么做?

旧网址:domain.com/medications/?drug=medication-title/has/slashes

新网址:domain.com/medications/medication-title-has-slashes

当前代码:

Options -MultiViews
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^medications/([^/]+)/?$ medications/?drug=$1 [QSA,L,NC]

【问题讨论】:

    标签: regex .htaccess mod-rewrite


    【解决方案1】:

    为此提出了一个 PHP 解决方案。但如果有人找到解决方案,请保持开放状态。

    PHP: $str = str_replace("/", '-', $str);

    【讨论】:

      猜你喜欢
      • 2011-08-08
      • 2016-10-05
      • 1970-01-01
      • 1970-01-01
      • 2012-01-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-29
      相关资源
      最近更新 更多