0

我想达到什么目的?

我想将/migrate目录(和子目录)中的所有 URL 转换为小写。

我做了什么?

我已将我的网站从 DNN 迁移到 Wordpress。因此,我的帖子中有 URL,这些 URL 引用了大小写字母组合的图像。

/migrate文件夹(和子文件夹)中磁盘上的所有目录和文件都是小写的。

当我查看一篇文章时,如果对图像的引用包含大写字符,我会得到预期的 404。

例如:

https://xxx.domain.net/wp-content/migrate/ABC/image.jpg

https://xxx.domain.net/wp-content/migrate/Xyz/image.jpg

https://xxx.domain.net/wp-content/migrate/abc/Image.jpg

https://xxx.domain.net/wp-content/migrate/ABC/Xyz/image.jpg

所以在网上和这里阅读了各种文章后,我尝试了一些事情:

1) 启用 mod_speling 并将其添加到 apache2.conf

LoadModule speling_module /usr/lib/apache2/modules/mod_speling.so
<IfModule mod_speling.c>
CheckSpelling On
CheckCaseOnly On
</IfModule>

这没有用,继续得到404。

2) 厌倦了在我的 /etc/sites-enabled/mysite.conf 文件中使用 Rewritemap。

RewriteMap  lc int:tolower
RewriteCond %{REQUEST_URI} /migrate [A-Z]
RewriteRule  ^(.*)$ /${lc:$1} [R=301,L]

但是,这会将所有URL 重写为小写,并且由于磁盘上的文件具有大写字符,它会破坏一些 Wordpress 插件和编辑器。

我在 Wordpress 根目录下的 .htaccess 文件如下:

RewriteEngine on
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1]

RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]

#BEGIN Wordpress

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress
4

1 回答 1

0

经过数小时尝试不同的事情并阅读日志后,我已经解决了这个问题!

基本上我需要从重写中忽略所有其他 Wordpress 目录。

RewriteMap lc int:tolower
RewriteCond %{REQUEST_URI} [A-Z]
RewriteCond %{REQUEST_URI} !^/wp-content/uploads/
RewriteCond %{REQUEST_URI} !^/wp-content/themes/
RewriteCond %{REQUEST_URI} !^/wp-content/plugins/
RewriteCond %{REQUEST_URI} !^/wp-includes/
RewriteCond %{REQUEST_URI} !^/wp-admin/
RewriteRule ^/?(.*)$ /${lc:$1} [R=301,L]
于 2018-12-03T09:15:08.057 回答