Wordpress 转义编码(十六进制)URL 区分大小写问题

Wordpress 转义编码(十六进制)URL 区分大小写问题

我昨天遇到了一个问题。我的网站是希伯来语的。我的网站是在 Wordpress 上构建的。问题仅与转义编码的帖子 URL 有关。如果帖子 URL 以大写字母转义编码,则它可以正常工作,如果以小写字母转义编码,则返回 404。我希望两者都能顺利通过。我的网站托管在 godaddy 共享主机上。是否有任何选项可以同时接受大写和小写字母并显示同一篇帖子?

例如: http://domain.com/%d7%9e%d7%a6%d7%9c%d7%9e%d7%95%d7%aa/ (这是我的网站所拥有的)

谷歌将其抓取如下: http://domain.com/%D7%9E%D7%a6%D7%9C%D7%9E%D7%95%D7%AA/ (返回 404)

我认为在 mod_rewrite (htaccess) 中我应该将 URL 传输到 wordpress 时不区分大小写。我该怎么做?

答案1

根据您的示例 URL,您希望 URL 以小写形式转义,如果您可以控制您的服务器或虚拟主机,您可以定义一个 tolower 映射并在您的重写规则中使用它,如下所示:

RewriteEngine On
RewriteMap  tolower int:tolower
RewriteCond %{REQUEST_URI} [a-z]
RewriteRule (.*) ${tolower:$1} [R=301,L]

您还可以在自己的 htaccess 中完成并使用以下代码:

Options +FollowSymLinks
RewriteEngine on
# If the URI does not contain any uppercase letters, skip the next 28 rules.
RewriteRule ![A-Z] - [S=28]
#
# Else convert the first instance of "A" to "a", "B" to "b", etc.
RewriteRule ([^A]*)A(.*) $1a$2
RewriteRule ([^B]*)B(.*) $1b$2
# <22 more rules>
RewriteRule ([^Y]*)Y(.*) $1y$2
RewriteRule ([^Z]*)Z(.*) $1z$2
#
# If any more uppercase characters remain, restart mod_rewrite from the top
RewriteRule [A-Z] - [PT,N]
# Otherwise do an external 301 redirect to give the client the new URL.
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
#
# Skip to here if no uppercase letters in client-requested URL.
# <some other rules>

如果您无法控制服务器,您还可以使用 wordpress 重定向插件将所有传入的 URL 转换为小写。(s/[AZ]/\l&/g)

http://wordpress.org/extend/plugins/permalowercase301/

另一个解决方案是更改您的 404 错误页面以检测此类链接并重定向它们。

http://www.unfocus.com/2007/08/31/case-insensitive-permalinks-plugin-for-wordpress/

相关内容