【问题标题】:Url underscore to hyphen rewrite fails for more than ten underscores网址下划线到连字符重写失败超过十个下划线
【发布时间】:2013-12-31 12:05:51
【问题描述】:

我正在使用.htaccess 中的此代码将下划线改写为网址中的连字符

RewriteRule ^([^_]+)_(.+?\.html)$ $1-$2 [L,NC,E=underscores:Yes]

RewriteCond %{ENV:REDIRECT_underscores} ^Yes$
RewriteRule ^([^_]+)$ /$1 [R=301,L]

很遗憾,如果下划线超过十个,代码就会失败。我什至可以将下划线一一更改为连字符以减少数字,然后页面会重定向。例如 改变

http://www.astarmathsandphysics.com/igcse_maths_notes/igcse_maths_notes_cumulative_frequency_curves_quartiles_interquartile_range_and_median.html

http://www.astarmathsandphysics.com/igcse_maths_notes/igcse_maths_notes_cumulative_frequency_curves_quartiles_interquartile_range-and-median.html

如何更改代码以重定向任意数量的下划线

【问题讨论】:

  • 在问题中发布正确重写的 URL 示例。它可能是其他东西,比如文件名大小的限制。
  • 您正在达到内部重写限制。默认设置为 10。如果您 100%(检查、检查、仔细检查)确定您的 .htaccess 是稳定的,则可以使用 [N] 标志。不过要非常小心。如果由于某种原因重写永远不会停止,您的 Apache 将会崩溃,并且您的错误日志将会非常庞大​​。您可能需要使用[DPI](丢弃路径信息)标志才能使其工作。如果我考虑一下,我可能会在稍后发布答案。现在:见docs

标签: apache mod-rewrite hyphen


【解决方案1】:

您的 limitinternalrecursion 参数设置为 10。因此在 10 次替换后它放弃了。 Apache 试图保护您免受重写规则中的无限递归。

http://httpd.apache.org/docs/2.2/mod/core.html#limitinternalrecursion

LimitInternalRecursion 的默认值为 10

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-06-05
    • 2013-09-05
    • 2019-02-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-20
    相关资源
    最近更新 更多