【问题标题】:Allow space and other special characters in htaccess url rewrite在 htaccess url 重写中允许空格和其他特殊字符
【发布时间】:2015-09-01 04:05:24
【问题描述】:

大家好,我有这个网址:orderprod_cntr/147/ok2%20-%20val1%20val2%20val3%20val4

当我打开此 URL 时,我会收到 404 错误。

我目前使用的htaccess规则是:

RewriteRule orderprod_cntr/([-\w]+)/([-\w]+)/?$   controller/orderprod_cntr.php?id1=$1&id2=$2 [L]

由于 URL 中的%20 而发生错误,没有它可以正常工作。 请告诉我用于上述网址的正确规则。 谢谢

【问题讨论】:

  • 投反对票前的评论将有助于我编辑我的问题。

标签: php regex apache .htaccess mod-rewrite


【解决方案1】:

基于How to redirect %20 or White space automatically to + or - with htaccess?我建议:

RewriteRule orderprod_cntr/((-|\w|%20)+)/((-|\w|%20)+) controller/orderprod_cntr.php?id1=$1&id2=$4 [L]

【讨论】:

    【解决方案2】:

    你可以像这样调整你的正则表达式:

    RewriteRule orderprod_cntr/([^/]+)/([^/]+)/?$ controller/orderprod_cntr.php?id1=$1&id2=$2 [L,QSA]
    

    【讨论】:

    • 上面的正则表达式的意思是允许url参数中的任何特殊字符对吧?
    • 是的,它允许除/ 之外的任何内容。很高兴它奏效了。问题是公平的,不公平地被否决了。所以从我这边+1
    • @anubhava 如果您有时间,请检查我的问题:QUESTION
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-30
    相关资源
    最近更新 更多