【问题标题】:How to match right single quotation mark character in an Apache RewriteRule如何在 Apache RewriteRule 中匹配右单引号字符
【发布时间】:2015-04-01 12:03:49
【问题描述】:

我正在尝试获取以下网址:

http://olddomain.com/macmillan’s-st-luke-passion

其中包含右单引号字符 (http://www.fileformat.info/info/unicode/char/2019/index.htm)

重定向到新位置。但是,我无法让 Apache 执行此操作。

作为参考,我的重定向代码(在 VirtualHost 中)如下:

RewriteEngine on
RewriteRule ^macmillan\xE2\x80\x99s-st-luke-passion$ http://newdomain.com/tickets/events/macmillans-st-luke-passion [R=301,L]

该文件还有其他用于精确匹配 URL 的重定向,其中一个在页面底部捕获所有重定向。这一个旨在将任何剩余的 URL 匹配到 /events/(old url)。例如,它会将olddomain.com/page-title 发送到newdomain.com/events/page-title

Redirect 301 / https://newdomain.com/events/

目前发生的情况是 Apache 忽略了包含右引号字符 \x 编码字符串的特定规则。

然后通过后备重定向将 URL 发送到错误的位置。

谁能帮助解决如何在 Apache RewriteRule(或 RedirectMatch)中将 URL 与右引号字符 匹配?

【问题讨论】:

    标签: apache .htaccess mod-rewrite


    【解决方案1】:

    在虚拟主机配置文件中试试这个规则:

    RewriteEngine on
    
    RewriteRule ^/?macmillan\xE2\x80\x99s-st-luke-passion$ http://newdomain.com/tickets/events/macmillans-st-luke-passion [NC,R=301,L]
    

    在 Apache 或 vhost 配置中匹配时需要前导斜杠,但在 htaccess 中使用时不需要。确保在新浏览器中测试以避免旧缓存。

    【讨论】:

    • 在正则表达式模式的开头添加 / 效果很好,谢谢。忘记 / 规则了!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-02
    • 2015-03-24
    • 1970-01-01
    • 1970-01-01
    • 2010-09-10
    相关资源
    最近更新 更多