apache - 如何在 Apache RewriteRule 中匹配正确的单引号字符

标签 apache .htaccess mod-rewrite

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

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-titlenewdomain.com/events/page-title .
Redirect 301 / https://newdomain.com/events/

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

并落入将 URL 发送到错误位置的回退重定向。

任何人都可以帮助如何将 URL 与正确的引号字符匹配 在 Apache RewriteRule 中(或 RedirectMatch)?

最佳答案

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

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 中使用时不需要。确保在新浏览器中进行测试以避免旧缓存。

关于apache - 如何在 Apache RewriteRule 中匹配正确的单引号字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29390309/

相关文章:

java - 仅当安装了证书时才访问页面

php - 碎片化的网址导致 SEO 出现问题

apache - 从 http 基本身份验证中排除特定的 cakephp Controller

linux - 在我的 htaccess 中重定向导致 503 服务器太忙

php - 具有多个变量的 Mod_rewrite

apache - 具有 apache2 反向代理 ssl 握手的 celery 花对于 websocket 失败

ruby - 我如何绝对确保 Phusion Passenger 实例保持事件状态?

php - php中的mysql查询循环

apache - 在 Mountain Lion libtool 问题上构建 Apache

.htaccess - 使用 .htaccess 将 www URL 重定向到 https 的非 www