【问题标题】:How to Redirect an URL with special characters %ef%bb%bf?如何重定向带有特殊字符%ef%bb%bf的URL?
【发布时间】:2020-07-16 09:34:36
【问题描述】:

我的 Wordpress 网站上有 URL 末尾带有 %ef%bb%bf 的链接,我直接在数据库中更改了它们,但我知道我必须将旧链接重定向到新版本。

我尝试通过 .htaccess,但它不起作用:

Redirect 301 /category/old-uri%ef%bb%bf/ https://example.com/category/new-uri

我也尝试了不同的变体,但没有任何效果。

你有什么想法吗?

谢谢

【问题讨论】:

  • 当您请求与此 .htaccess 的旧链接时会发生什么?确保安装在同一目录中的任何.htaccess 文件都可以正常工作。
  • 什么也没发生。显示带有旧网址的旧页面。重定向不起作用。我尝试了没有 %ef%bb%bf 的部分:Redirect 301 /category/ mywebsite.com/category/new-uri 并且这是正确的。
  • 好的,然后检查this questionthis
  • 最后一个字符是 HTML 实体,当我使用 HTML 表 krypted.com/utilities/html-encoding-reference 时,我得到了这些字符:
  • 我尝试了 RewriteRule 指令而不是重定向 301,但重定向仍然不顺利,我得到了 404。我的代码:RewriteRule /category/old-uri%ef%bb%bf/ 示例.com/category/new-uri [B, R=301]

标签: php wordpress .htaccess url special-characters


【解决方案1】:

您必须添加 B 重写标志。此标志告诉 mod_rewrite 转义反向引用,如 @Accountant 链接中的 this answer 中所述。

Redirect 301 /category/old-uri%ef%bb%bf/ https://example.com/category/new-uri [B]

将转义特殊字符并将https://example.com/category/old-uri%ef%bb%bf/ 引导至新网址https://example.com/category/new-uri

【讨论】:

  • 它在行尾添加了 [B,它] 给了我整个网站的“内部服务器错误”。
  • 嗨 Gael,我只是使用了 RewriteRule 指令而不是重定向 301。我不再收到内部服务器错误,但重定向仍然不顺利,我收到 404。我的代码:RewriteRule /类别/old-uri%ef%bb%bf/ example.com/category/new-uri [B, R=301]
  • 您的 htaccess 中是否还有其他可能导致内部服务器错误的规则?我的答案中的代码在我的测试网站上正常工作。
  • 该代码被封装在一个 但在此之前,是的,还有其他规则,在其他 中像这样:
  • # BEGIN WordPress # Les directives (lignes) entre 'BEGIN WordPress' et 'END WordPress' sont # généré dynamiquement, et ne doivent uniquement être modifiées via les filtres WordPress。 # Toute 修改 des 指令 entre ces marqueurs sera outrepassée。 RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule 。 /index.php [L] # 结束 WordPress
猜你喜欢
  • 1970-01-01
  • 2019-01-05
  • 1970-01-01
  • 2016-04-13
  • 2012-02-18
  • 1970-01-01
  • 2018-05-12
  • 1970-01-01
  • 2015-05-19
相关资源
最近更新 更多